Crashing on layout

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3352
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Crashing on layout

Post by ONEEYEMAN » Wed Feb 13, 2019 1:39 pm

Hi, ALL,

Code: Select all

FieldGeneral::FieldGeneral(wxWindow *parent) : wxPanel(parent, wxID_ANY)
{
    m_label = new wxStaticText( this, wxID_ANY, _( "&Column comment:" ) );
    m_comment = new wxTextCtrl( this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
    m_log = new wxCheckBox( this, wxID_ANY, _( "&Log Only" ) );
    do_layout();
}

FieldGeneral::~FieldGeneral()
{
}

void FieldGeneral::do_layout()
{
    wxBoxSizer *sizer1 = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer *sizer2 = new wxBoxSizer( wxVERTICAL );
    wxBoxSizer *sizer3 = new wxBoxSizer( wxVERTICAL );
    sizer1->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer2->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer3->Add( m_label, 0, wxEXPAND, 0 );
    sizer3->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer3->Add( m_comment, 0, wxEXPAND, 0 );
    sizer3->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer3->Add( m_log, 0, wxEXPAND, 0 );
    sizer2->Add( sizer3, 0, wxEXPAND, 0 );
    sizer2->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer1->Add( sizer1, 0, wxEXPAND, 0 );
    sizer1->Add( 5, 5, 0, wxEXPAND, 0 );
    SetSizer( sizer1 );
}

Code: Select all

PropertiesDialog::PropertiesDialog(wxWindow* parent, wxWindowID id, const wxString& title):
    wxDialog(parent, id, title, pos, size, style)
{
    m_properties = new wxNotebook( this, wxID_ANY );
     m_page5 = new FieldGeneral( m_properties );
     m_properties->AddPage( m_page5, _( "General" ) );
    wxBoxSizer* sizer_1 = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer* sizer_2 = new wxBoxSizer( wxVERTICAL );
    wxBoxSizer* sizer_3 = new wxBoxSizer( wxVERTICAL );
    wxSizer* buttonSizer = CreateButtonSizer( wxOK | wxCANCEL | wxAPPLY | wxHELP );
    sizer_1->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_2->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_3->Add( m_properties, 0, wxEXPAND, 0 );
    sizer_3->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_3->Add( buttonSizer, 0, wxEXPAND, 0 );
    sizer_2->Add( sizer_3, 0, wxEXPAND, 0 );
    sizer_2->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer_1->Add( sizer_2, 0, wxEXPAND, 0 );
    sizer_1->Add( 5, 5, 0, wxEXPAND, 0 );
    SetSizerAndFit( sizer_1 );
}
The last line (SetSizerAndFit) causes a crash for SO.

Could someone spot an error?

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 13874
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Crashing on layout

Post by doublemax » Wed Feb 13, 2019 2:06 pm

In do_layout:

Code: Select all

sizer1->Add( sizer1, 0, wxEXPAND, 0 );
Adding the sizer to itself doesn't look right :)
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3352
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Crashing on layout

Post by ONEEYEMAN » Wed Feb 13, 2019 4:06 pm

I feel embarrassed. :oops:

Thank you, doublemax.

Sometimes you just need a fresh pair of eyes.

Post Reply