From b0067f83cadb98c47d7afd87fcdbee9ec28376fc Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Sat, 20 Nov 2021 10:30:32 +0100 Subject: [PATCH] hourglass: fix segfault, repeatable with: for(int i = 1; i < 10000; i++){hg.paint();hg.hide();} --- src/gui/widget/hourglass.cpp | 9 +++++++-- src/gui/widget/hourglass.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gui/widget/hourglass.cpp b/src/gui/widget/hourglass.cpp index ee91793b8..86f1eedd5 100644 --- a/src/gui/widget/hourglass.cpp +++ b/src/gui/widget/hourglass.cpp @@ -70,8 +70,11 @@ CHourGlass::CHourGlass( const int x_pos, CHourGlass::~CHourGlass() { - delete hg_timer; - hg_timer = NULL; + if(hg_timer) + { + delete hg_timer; + hg_timer = NULL; + } } void CHourGlass::initImageFiles() @@ -101,6 +104,8 @@ void CHourGlass::paint(const bool &do_save_bg) if (hg_img_files.empty()) return; + std::lock_guard g(hg_mutex); + if (hg_file_num > hg_img_files.size()-1) hg_file_num = 0; diff --git a/src/gui/widget/hourglass.h b/src/gui/widget/hourglass.h index 29a40b1ba..4807fb578 100644 --- a/src/gui/widget/hourglass.h +++ b/src/gui/widget/hourglass.h @@ -43,7 +43,7 @@ class CHourGlass : public CComponentsShapeSquare int64_t hg_interval; CComponentsTimer *hg_timer; size_t hg_file_num; - + std::mutex hg_mutex; void initImageFiles(); public: /**CHourGlass Constructor