Prevent segfaults from callbacks when statusbar elements are deallocated

happens on application exit when a job (arrange or optimize orientation) is running.
This commit is contained in:
tamasmeszaros 2019-05-13 10:20:37 +02:00
parent 80d8adc70a
commit 52d042a1c9

View File

@ -67,16 +67,18 @@ ProgressStatusBar::ProgressStatusBar(wxWindow *parent, int id):
} }
ProgressStatusBar::~ProgressStatusBar() { ProgressStatusBar::~ProgressStatusBar() {
if(m_timer->IsRunning()) m_timer->Stop(); if(m_timer && m_timer->IsRunning()) m_timer->Stop();
} }
int ProgressStatusBar::get_progress() const int ProgressStatusBar::get_progress() const
{ {
return m_prog->GetValue(); return m_prog ? m_prog->GetValue() : 0;
} }
void ProgressStatusBar::set_progress(int val) void ProgressStatusBar::set_progress(int val)
{ {
if(!m_prog) return;
if(!m_prog->IsShown()) show_progress(true); if(!m_prog->IsShown()) show_progress(true);
if(val < 0) return; if(val < 0) return;
@ -91,24 +93,28 @@ void ProgressStatusBar::set_progress(int val)
int ProgressStatusBar::get_range() const int ProgressStatusBar::get_range() const
{ {
return m_prog->GetRange(); return m_prog ? m_prog->GetRange() : 0;
} }
void ProgressStatusBar::set_range(int val) void ProgressStatusBar::set_range(int val)
{ {
if(val != m_prog->GetRange()) { if(m_prog && val != m_prog->GetRange()) {
m_prog->SetRange(val); m_prog->SetRange(val);
} }
} }
void ProgressStatusBar::show_progress(bool show) void ProgressStatusBar::show_progress(bool show)
{ {
if(m_prog) {
m_prog->Show(show); m_prog->Show(show);
m_prog->Pulse(); m_prog->Pulse();
}
} }
void ProgressStatusBar::start_busy(int rate) void ProgressStatusBar::start_busy(int rate)
{ {
if(!m_prog) return;
m_busy = true; m_busy = true;
show_progress(true); show_progress(true);
if (!m_timer->IsRunning()) { if (!m_timer->IsRunning()) {
@ -118,6 +124,8 @@ void ProgressStatusBar::start_busy(int rate)
void ProgressStatusBar::stop_busy() void ProgressStatusBar::stop_busy()
{ {
if(!m_timer || !m_prog) return;
m_timer->Stop(); m_timer->Stop();
show_progress(false); show_progress(false);
m_prog->SetValue(0); m_prog->SetValue(0);
@ -126,13 +134,15 @@ void ProgressStatusBar::stop_busy()
void ProgressStatusBar::set_cancel_callback(ProgressStatusBar::CancelFn ccb) { void ProgressStatusBar::set_cancel_callback(ProgressStatusBar::CancelFn ccb) {
m_cancel_cb = ccb; m_cancel_cb = ccb;
if(m_cancelbutton) {
if(ccb) m_cancelbutton->Show(); if(ccb) m_cancelbutton->Show();
else m_cancelbutton->Hide(); else m_cancelbutton->Hide();
}
} }
void ProgressStatusBar::run(int rate) void ProgressStatusBar::run(int rate)
{ {
if(!m_timer->IsRunning()) { if(m_timer && !m_timer->IsRunning()) {
m_timer->Start(rate); m_timer->Start(rate);
} }
} }
@ -140,12 +150,12 @@ void ProgressStatusBar::run(int rate)
void ProgressStatusBar::embed(wxFrame *frame) void ProgressStatusBar::embed(wxFrame *frame)
{ {
wxFrame* mf = frame ? frame : GUI::wxGetApp().mainframe; wxFrame* mf = frame ? frame : GUI::wxGetApp().mainframe;
mf->SetStatusBar(self); if(mf) mf->SetStatusBar(self);
} }
void ProgressStatusBar::set_status_text(const wxString& txt) void ProgressStatusBar::set_status_text(const wxString& txt)
{ {
self->SetStatusText(txt); if(self) self->SetStatusText(txt);
} }
void ProgressStatusBar::set_status_text(const std::string& txt) void ProgressStatusBar::set_status_text(const std::string& txt)
@ -160,12 +170,12 @@ void ProgressStatusBar::set_status_text(const char *txt)
void ProgressStatusBar::show_cancel_button() void ProgressStatusBar::show_cancel_button()
{ {
m_cancelbutton->Show(); if(m_cancelbutton) m_cancelbutton->Show();
} }
void ProgressStatusBar::hide_cancel_button() void ProgressStatusBar::hide_cancel_button()
{ {
m_cancelbutton->Hide(); if(m_cancelbutton) m_cancelbutton->Hide();
} }
} }