Fix crash due to logging bug in the event sample

The gestures frame created its own log target and deleted
the previous one but did not restore it when being closed.

This left the current log target invalid which led to a crash
when calling any wxLog*() function after gestures frame was closed.

Fix this by restoring the previous log target when gestures frame
is closed.

See #23767, #23881.

(cherry picked from commit 8efb1bceda202a26380e6491aa00504097a4bb26)
This commit is contained in:
PB 2023-09-18 15:24:27 +02:00 committed by Vadim Zeitlin
parent 119ba7bb48
commit 7ccdc6ac85
2 changed files with 3 additions and 1 deletions

View File

@ -23,7 +23,7 @@ MyGestureFrame::MyGestureFrame()
SetSizeHints(wxMin(800,dsplySz.GetWidth()), wxMin(600,dsplySz.GetHeight())); SetSizeHints(wxMin(800,dsplySz.GetWidth()), wxMin(600,dsplySz.GetHeight()));
// Log to the text control // Log to the text control
delete wxLog::SetActiveTarget(new wxLogTextCtrl(m_logText)); m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logText));
// Bind all gestures to the same event handler, which must run before // Bind all gestures to the same event handler, which must run before
// the other handlers, to clear the log window // the other handlers, to clear the log window
@ -64,6 +64,7 @@ MyGesturePanel::MyGesturePanel(MyGestureFrame *parent)
void MyGestureFrame::OnQuit(wxCloseEvent& WXUNUSED(event)) void MyGestureFrame::OnQuit(wxCloseEvent& WXUNUSED(event))
{ {
delete wxLog::SetActiveTarget(m_logOld);
Destroy(); Destroy();
} }

View File

@ -12,6 +12,7 @@ public:
void OnQuit(wxCloseEvent& event); void OnQuit(wxCloseEvent& event);
private: private:
wxLog *m_logOld;
wxTextCtrl *m_logText; wxTextCtrl *m_logText;
}; };