User forums > General (but related to Code::Blocks)

wxSmith GetSizer()->SetSizeHints(this); causes crash

(1/1)

kodestiff:
Hello

In WxSmith Tutorial 6 ( http://wiki.codeblocks.org/index.php?title=WxSmith_tutorial:_Accessing_items_in_resource#Using_value_from_wxSlider_to_change_font_size) the following code causes Tutorial6.exe to crash:

--- Code: ---void Tutorial6Frame::OnSlider1CmdScrollThumbRelease(wxScrollEvent& event)
{
    Layout();
    GetSizer()->SetSizeHints(this);
}


--- End code ---

As soon as I remove GetSizer()->SetSizeHints(this);, everything works fine.

I have WxWidgets 2.8 and C::B 8.02 with MinGW 5.1.6 on WindowsXP Pro (32), SP2

Any idea why?


[attachment deleted by admin]

Jenna:
There are several minor versions of wxWidgets 2.8, that are not fully compatible.

But I don't think this is the problem.

Are you sure you GetSizer() returns a valid pointer ?


--- Quote from: wxWidgets docu ---wxWindow::GetSizer

wxSizer * GetSizer() const

Return the sizer associated with the window by a previous call to SetSizer() or NULL.
--- End quote ---

You can try something like:

--- Code: ---if (GetSizer()) GetSizer()->SetSizeHints(this);
--- End code ---
and see whether the error still occurs or not.

kodestiff:
Thank you very much Jens

Your solution stopped the crash, but I suspect the code isn't working as intended:

--- Code: ---void Tutorial_6Frame::OnSlider1CmdScrollThumbRelease(wxScrollEvent& event)
{
    Layout();
    GetSizer()->SetSizeHints(this);
}

--- End code ---
(as given in the tutorial)

--- Quote ---In the first line we adopt positions of items to new environment just like in case of changing label in wxStaticText. In the second line we recalculate minimal size of the window making sure that all items will have enough space. 
--- End quote ---

It seems that it should let the window grow to make space for the overgrown label, but that doesn't happen.  I assume GetSizer() returned false...

Could you please point me to the wxWidgets documentation.  I have only found the tutorials.

Greetings from Innsbruck

[attachment deleted by admin]

Jenna:
I never used the tutorial.

The easiest way to find the wxwidgets-docu is to go to wxwidgets.org and click on Documentation in the quick links section.

If you have installed the wxwidgets sources on windows, you should have a link to the chm-file in the startmenu, on linux you can install the wx2.8-doc package (that's the debian name, might be called differently in other distros).

Navigation

[0] Message Index

Go to full version