Fix crash in the splitter sample due to replacing null window

The sample could crash after the following sequence of actions:

1. Resize splitter to hide the right/left window.
2. Activate replace menu action.

Fix this by checking if the window being replaced is non-null.

Closes https://github.com/wxWidgets/wxWidgets/pull/1672
This commit is contained in:
Xiaofeng Wang
2019-12-07 11:12:58 +08:00
committed by Vadim Zeitlin
parent 9fbf97ae97
commit 1222ac3d7f

View File

@@ -448,8 +448,10 @@ void MyFrame::OnReplace(wxCommandEvent& WXUNUSED(event) )
{ {
if (m_replacewindow == NULL) { if (m_replacewindow == NULL) {
m_replacewindow = m_splitter->GetWindow2(); m_replacewindow = m_splitter->GetWindow2();
m_splitter->ReplaceWindow(m_replacewindow, new wxPanel(m_splitter, wxID_ANY)); if (m_replacewindow != NULL) {
m_replacewindow->Hide(); m_splitter->ReplaceWindow(m_replacewindow, new wxPanel(m_splitter, wxID_ANY));
m_replacewindow->Hide();
}
} else { } else {
wxWindow *empty = m_splitter->GetWindow2(); wxWindow *empty = m_splitter->GetWindow2();
wxASSERT(empty != m_replacewindow); wxASSERT(empty != m_replacewindow);