X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/90e95e61175953284a40c73f1d62ccc18ef4c748..14619f10b0bdb630206607abd0ce0319d45e095a:/samples/thread/thread.cpp?ds=sidebyside diff --git a/samples/thread/thread.cpp b/samples/thread/thread.cpp index b6adc3846d..7948c35a47 100644 --- a/samples/thread/thread.cpp +++ b/samples/thread/thread.cpp @@ -597,6 +597,8 @@ void MyFrame::OnStartThread(wxCommandEvent& WXUNUSED(event) ) void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) ) { + wxThread* toDelete = NULL; + { wxCriticalSectionLocker enter(wxGetApp().m_critsect); // stop the last thread @@ -606,7 +608,15 @@ void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) ) } else { - wxGetApp().m_threads.Last()->Delete(); + toDelete = wxGetApp().m_threads.Last(); + } + } + + if ( toDelete ) + { + // This can still crash if the thread gets to delete itself + // in the mean time. + toDelete->Delete(); #if wxUSE_STATUSBAR SetStatusText(wxT("Last thread stopped."), 1);