Author Topic: wxSmith GetSizer()->SetSizeHints(this); causes crash  (Read 3936 times)

Offline kodestiff

  • Multiple posting newcomer
  • *
  • Posts: 13
wxSmith GetSizer()->SetSizeHints(this); causes crash
« on: January 24, 2010, 01:28:59 pm »
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);
}


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]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: wxSmith GetSizer()->SetSizeHints(this); causes crash
« Reply #1 on: January 24, 2010, 01:49:43 pm »
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.

You can try something like:
Code
if (GetSizer()) GetSizer()->SetSizeHints(this);
and see whether the error still occurs or not.

Offline kodestiff

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: wxSmith GetSizer()->SetSizeHints(this); causes crash
« Reply #2 on: January 24, 2010, 02:14:02 pm »
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);
}
(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. 

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]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: wxSmith GetSizer()->SetSizeHints(this); causes crash
« Reply #3 on: January 24, 2010, 02:29:02 pm »
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).