Crashes with nested sizers

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
Vexator
I live to help wx-kind
I live to help wx-kind
Posts: 187
Joined: Sun Jan 30, 2005 2:50 pm
Location: Heidelberg, Germany

Crashes with nested sizers

Post by Vexator » Tue Aug 16, 2011 6:54 pm

I'm experiencing crashes with nested sizers. I've got a panel which is populated with controls everytime a node on a treectrl is selected. I have the following code in my panel's constructor:

Code: Select all

m_buttonAdd = new wxButton( this, ID_ADD, _("Add") );
m_selectElement = new wxChoice( this, ID_CHOICE, wxDefaultPosition, wxSize(-1, -1), wxArrayString() );

m_boxSizer = new wxStaticBoxSizer( wxHORIZONTAL, this, "Entities" );
m_boxSizer->Add( m_selectElement, 0, wxALL | wxALIGN_CENTER_VERTICAL, 6 );
m_boxSizer->Add( m_buttonAdd, 0, wxALL | wxALIGN_CENTER_VERTICAL, 6 );

m_sizer->Add( m_boxSizer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 6 );

SetSizer( m_sizer );
Layout();
Now, when a node is selected, the following code is executed:

Code: Select all

m_sizer->Clear();
m_sizer->Add( m_boxSizer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 6 );
SetSizer( m_sizer );
Layout();
The application crashes while executing the second line, referencing line 336 in sizer.cpp:

Code: Select all

bool didUse = false;
// Pass the information along to the held object
if (IsSizer())
{
    didUse = GetSizer()->InformFirstDirection(direction,size,availableOtherDir); <--- CRASH
    if (didUse)
        m_minSize = GetSizer()->CalcMin();
}
Error message:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
It worked just fien when I added controls directly to m_sizer after clearing it, instead of the m_boxSizer. What's going on here? Thank you!
Windows 7 Pro
Visual Studio 2010
wxWidgets 2.9.3

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

Re: Crashes with nested sizers

Post by doublemax » Wed Aug 17, 2011 7:53 am

I don't know why this crashes, but i personally try to avoid dynamically detaching/adding items to sizers. I just Hide()/Show() controls inside the sizers. It's easier and 100% reliable.
Use the source, Luke!

Post Reply