hourglass: fix segfault, repeatable with: for(int i = 1; i < 10000; i++){hg.paint();hg.hide();}

This commit is contained in:
Jacek Jendrzej
2021-11-20 10:30:32 +01:00
parent 940d6473d9
commit b0067f83ca
2 changed files with 8 additions and 3 deletions

View File

@@ -69,10 +69,13 @@ CHourGlass::CHourGlass( const int x_pos,
} }
CHourGlass::~CHourGlass() CHourGlass::~CHourGlass()
{
if(hg_timer)
{ {
delete hg_timer; delete hg_timer;
hg_timer = NULL; hg_timer = NULL;
} }
}
void CHourGlass::initImageFiles() void CHourGlass::initImageFiles()
{ {
@@ -101,6 +104,8 @@ void CHourGlass::paint(const bool &do_save_bg)
if (hg_img_files.empty()) if (hg_img_files.empty())
return; return;
std::lock_guard<std::mutex> g(hg_mutex);
if (hg_file_num > hg_img_files.size()-1) if (hg_file_num > hg_img_files.size()-1)
hg_file_num = 0; hg_file_num = 0;

View File

@@ -43,7 +43,7 @@ class CHourGlass : public CComponentsShapeSquare
int64_t hg_interval; int64_t hg_interval;
CComponentsTimer *hg_timer; CComponentsTimer *hg_timer;
size_t hg_file_num; size_t hg_file_num;
std::mutex hg_mutex;
void initImageFiles(); void initImageFiles();
public: public:
/**CHourGlass Constructor /**CHourGlass Constructor