Ticket #14891: 14891_improve.diff

File 14891_improve.diff, 988 bytes (added by catalin, 5 years ago)
  • samples/thread/thread.cpp

     samples/thread/thread.cpp | 12 +++++++++++-
     1 file changed, 11 insertions(+), 1 deletion(-)
    
    diff --git a/samples/thread/thread.cpp b/samples/thread/thread.cpp
    index b6adc38..7948c35 100644
    a b void MyFrame::OnStartThread(wxCommandEvent& WXUNUSED(event) ) 
    597597
    598598void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) )
    599599{
     600    wxThread* toDelete = NULL;
     601    {
    600602    wxCriticalSectionLocker enter(wxGetApp().m_critsect);
    601603
    602604    // stop the last thread
    void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) ) 
    606608    }
    607609    else
    608610    {
    609         wxGetApp().m_threads.Last()->Delete();
     611        toDelete = wxGetApp().m_threads.Last();
     612    }
     613    }
     614
     615    if ( toDelete )
     616    {
     617        // This can still crash if the thread gets to delete itself
     618        // in the mean time.
     619        toDelete->Delete();
    610620
    611621#if wxUSE_STATUSBAR
    612622        SetStatusText(wxT("Last thread stopped."), 1);