Code::Blocks 16.01 with WxWidgets wxMSW 3.1.0 running on Windows 10
I am using wxSmith to create a dialog-based application and its code. When I build and run it, it crashes with a segmentation fault. I first reported this on the wxWidgets forum, and the discussion led to a solution which was to delete two extra spurious lines of code generated by wxSmith in the dialog constructor.
It crashes with a segmentation fault in wxWindowBase::InformFirstDirection(...) because when it calls GetSizer() to use as a pointer, that function is returning zero. This is line 871 in wincmn.cpp.
I reduced my wxWidgets project to a trivial case which is a wxDialog containing a wxBoxSizer (horizontal) which contains a wxPanel containing a second wxBoxSizer (vertical).
The unmodified code generated in the constructor by wxSmith is as follows:
{
wxBoxSizer* BoxSizer2;
wxBoxSizer* BoxSizer1;
Create(parent, wxID_ANY, _("Spine"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxSize(137,566), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
BoxSizer2 = new wxBoxSizer(wxVERTICAL);
Panel1->SetSizer(BoxSizer2);
SetSizer(BoxSizer2);
Layout();
BoxSizer1->Add(Panel1, 1, wxALL, 5);
SetSizer(BoxSizer1);
BoxSizer1->Fit(this); //<--- SEG FAULT IN THIS CALL
BoxSizer1->SetSizeHints(this);
}
The solution was to comment out (or remove) the two lines
SetSizer(BoxSizer2);
Layout();
(Note that SetSizer(BoxSizer2) is called twice for different windows.) The program then compiles and runs correctly. An additional problem is that each time the dialog is modified, those two lines re-appear and have to be commented out again.