From 52d042a1c9dea82d10f5e658faf7187f195754de Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Mon, 13 May 2019 10:20:37 +0200 Subject: [PATCH] Prevent segfaults from callbacks when statusbar elements are deallocated happens on application exit when a job (arrange or optimize orientation) is running. --- src/slic3r/GUI/ProgressStatusBar.cpp | 36 ++++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/ProgressStatusBar.cpp b/src/slic3r/GUI/ProgressStatusBar.cpp index 2f1937623..b48c5732b 100644 --- a/src/slic3r/GUI/ProgressStatusBar.cpp +++ b/src/slic3r/GUI/ProgressStatusBar.cpp @@ -67,16 +67,18 @@ ProgressStatusBar::ProgressStatusBar(wxWindow *parent, int id): } ProgressStatusBar::~ProgressStatusBar() { - if(m_timer->IsRunning()) m_timer->Stop(); + if(m_timer && m_timer->IsRunning()) m_timer->Stop(); } int ProgressStatusBar::get_progress() const { - return m_prog->GetValue(); + return m_prog ? m_prog->GetValue() : 0; } void ProgressStatusBar::set_progress(int val) { + if(!m_prog) return; + if(!m_prog->IsShown()) show_progress(true); if(val < 0) return; @@ -91,24 +93,28 @@ void ProgressStatusBar::set_progress(int val) int ProgressStatusBar::get_range() const { - return m_prog->GetRange(); + return m_prog ? m_prog->GetRange() : 0; } void ProgressStatusBar::set_range(int val) { - if(val != m_prog->GetRange()) { + if(m_prog && val != m_prog->GetRange()) { m_prog->SetRange(val); } } void ProgressStatusBar::show_progress(bool show) { - m_prog->Show(show); - m_prog->Pulse(); + if(m_prog) { + m_prog->Show(show); + m_prog->Pulse(); + } } void ProgressStatusBar::start_busy(int rate) { + if(!m_prog) return; + m_busy = true; show_progress(true); if (!m_timer->IsRunning()) { @@ -118,6 +124,8 @@ void ProgressStatusBar::start_busy(int rate) void ProgressStatusBar::stop_busy() { + if(!m_timer || !m_prog) return; + m_timer->Stop(); show_progress(false); m_prog->SetValue(0); @@ -126,13 +134,15 @@ void ProgressStatusBar::stop_busy() void ProgressStatusBar::set_cancel_callback(ProgressStatusBar::CancelFn ccb) { m_cancel_cb = ccb; - if(ccb) m_cancelbutton->Show(); - else m_cancelbutton->Hide(); + if(m_cancelbutton) { + if(ccb) m_cancelbutton->Show(); + else m_cancelbutton->Hide(); + } } void ProgressStatusBar::run(int rate) { - if(!m_timer->IsRunning()) { + if(m_timer && !m_timer->IsRunning()) { m_timer->Start(rate); } } @@ -140,12 +150,12 @@ void ProgressStatusBar::run(int rate) void ProgressStatusBar::embed(wxFrame *frame) { wxFrame* mf = frame ? frame : GUI::wxGetApp().mainframe; - mf->SetStatusBar(self); + if(mf) mf->SetStatusBar(self); } 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) @@ -160,12 +170,12 @@ void ProgressStatusBar::set_status_text(const char *txt) void ProgressStatusBar::show_cancel_button() { - m_cancelbutton->Show(); + if(m_cancelbutton) m_cancelbutton->Show(); } void ProgressStatusBar::hide_cancel_button() { - m_cancelbutton->Hide(); + if(m_cancelbutton) m_cancelbutton->Hide(); } }