From 40ac0fad072f4fb308c9b104a06ffc398106fa45 Mon Sep 17 00:00:00 2001 From: ckath Date: Thu, 12 Sep 2019 21:31:58 +0200 Subject: [PATCH] fix crashes during resizing - safeguard ncurses functions called within resize handler - stop refresh_layout from being called while directories are loading - resolves #20 --- ext/sncurses.c | 18 ++++++++++++++++++ ext/sncurses.h | 2 ++ fuf.c | 9 ++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ext/sncurses.c b/ext/sncurses.c index f1abbc0..212182f 100644 --- a/ext/sncurses.c +++ b/ext/sncurses.c @@ -16,6 +16,24 @@ sinit_pair(short pair, short f, short b) return r; } +int +sendwin(void) +{ + pthread_mutex_lock(&ncurses_lock); + int r = endwin(); + pthread_mutex_unlock(&ncurses_lock); + return r; +} + +int +srefresh(void) +{ + pthread_mutex_lock(&ncurses_lock); + int r = refresh(); + pthread_mutex_unlock(&ncurses_lock); + return r; +} + WINDOW * snewwin(int nlines, int ncols, int begin_y, int begin_x) { diff --git a/ext/sncurses.h b/ext/sncurses.h index c03cab8..6a1f974 100644 --- a/ext/sncurses.h +++ b/ext/sncurses.h @@ -3,6 +3,8 @@ #include int sinit_pair(short pair, short f, short b); +int sendwin(void); +int srefresh(void); WINDOW *snewwin(int nlines, int ncols, int begin_y, int begin_x); int sdelwin(WINDOW *win); int sbox(WINDOW *win, chtype verch, chtype horch); diff --git a/fuf.c b/fuf.c index 2dcede2..ac6109a 100644 --- a/fuf.c +++ b/fuf.c @@ -51,15 +51,18 @@ char preview_path[PATH_MAX]; static void handle_redraw() { - endwin(); - refresh(); + sendwin(); + srefresh(); /* keep the file list within resized window */ scroll_pos = items_len-1 > scroll_pos-LINES+2 ? items_len-1-LINES+2 : items_len-scroll_pos < LINES+2 ? 0 : scroll_pos; - refresh_layout(); + extern bool items_loading; + if (!items_loading) { + refresh_layout(); + } } static void