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

Origin commit data
------------------
Commit: 4c1d17c4b5
Author: Jacek Jendrzej <overx300@gmail.com>
Date: 2021-11-20 (Sat, 20 Nov 2021)
This commit is contained in:
Jacek Jendrzej
2021-11-20 18:42:49 +01:00
committed by vanhofen
parent 1b2f3bc103
commit a64b6ebcbb
2 changed files with 8 additions and 3 deletions

View File

@@ -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<std::mutex> g(hg_mutex);
if (hg_file_num > hg_img_files.size()-1)
hg_file_num = 0;

View File

@@ -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