Author Topic: WxSmith generate wrong code with sizer  (Read 6800 times)

Offline gst0098

  • Single posting newcomer
  • *
  • Posts: 4
WxSmith generate wrong code with sizer
« on: June 25, 2014, 01:24:39 pm »
Platform: CodeBlocks 13.12, ArchLinux

wxSmith generates code that cause segfault when executed, this is an exerpt of the generated code:

Code
    inner_sizer->Add(Panel7, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    Panel5->SetSizer(inner_sizer);
    SetSizer(inner_sizer);
    Layout();

When executed it segfaults at the Layout() line. The above code is assigning the same sizer to multiple windows, is this correct ? I believe not and in fact I found that commenting the SetSizer(inner_sizer) line solves the problem and the program runs.

Thanks in advance,
Giuseppe

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re:
« Reply #1 on: June 25, 2014, 08:12:58 pm »
Please provide a sample project to reproduce.it looks more like a wx layout issue to me...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline gst0098

  • Single posting newcomer
  • *
  • Posts: 4
Re:
« Reply #2 on: June 30, 2014, 02:35:45 pm »
Please provide a sample project to reproduce.it looks more like a wx layout issue to me...

The project is big, I extracted in a new project only some parts of the UI, the behaviour is exactly as the orginal project, wxSmith apprently generates wrong code.

The project is attached.

Thanks,
Giuseppe
« Last Edit: July 04, 2014, 09:56:09 am by gst0098 »

Offline gst0098

  • Single posting newcomer
  • *
  • Posts: 4
Re:
« Reply #3 on: July 21, 2014, 03:59:36 pm »
Still I can't find any workaorunds to the problem, the problems looks related to the way wxSmith generate code for the layout manager, it duplicates the assignment of the the same sizer to different panels, this generates the segfault.

I'm hoping this behaviour will be fixed in future releases.

I cannot understand why no one as reported this before.
Is anyone kind to try the attached code ? Maybe the problem is related to my configuration/installation.

Giuseppe

Please provide a sample project to reproduce.it looks more like a wx layout issue to me...

The project is big, I extracted in a new project only some parts of the UI, the behaviour is exactly as the orginal project, wxSmith apprently generates wrong code.

The project is attached.

Thanks,
Giuseppe

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re:
« Reply #4 on: July 21, 2014, 05:44:57 pm »
Still I can't find any workaorunds to the problem, the problems looks related to the way wxSmith generate code for the layout manager, it duplicates the assignment of the the same sizer to different panels, this generates the segfault.

I'm hoping this behaviour will be fixed in future releases.

I cannot understand why no one as reported this before.
Is anyone kind to try the attached code ? Maybe the problem is related to my configuration/installation.

Giuseppe

Guiseppe,

I tried your code quickly under Kubuntu 14.04 and using wx3.0. Sure enough it caused problems. However I cannot say exactly why. It seems strange that Layout() is called several times (6 times!!) in your main frame constructor. I think somehow you've managed to fool the system.

But your code seems overly complex using FlexGridSizer etc. in many layers. In my experience this can be asking for trouble. I started deleting until it worked, but I couldn't pinpoint the issue directly. I would recommend keeping the number of layers in the GUI design less complicated. One way I have done that is using only wxBoxSizers vertical/horizontal as needed, it tends to work fine (many layers also, but simpler).

But lately, I have started using wxAUI for these things. It looks better, it is easier to use and far more flexible with docking support etc. Generally drop a wxAuiManager into the main frame, and add panels to it.

Whether or not I use AUI, I tend to create custom panels (all the time using wxSmith) and add them to notebooks or AUI. I find that the application structure becomes cleaner (IMHO) that way.

So I think you have to prototype a layout until you find something that works. Test for every new complexity you add, so you are able to identify where problems begin.

Offline gst0098

  • Single posting newcomer
  • *
  • Posts: 4
Re:
« Reply #5 on: July 22, 2014, 05:09:23 pm »
Quote
Guiseppe,

I tried your code quickly under Kubuntu 14.04 and using wx3.0. Sure enough it caused problems. However I cannot say exactly why. It seems strange that Layout() is called several times (6 times!!) in your main frame constructor. I think somehow you've managed to fool the system.

But your code seems overly complex using FlexGridSizer etc. in many layers. In my experience this can be asking for trouble. I started deleting until it worked, but I couldn't pinpoint the issue directly. I would recommend keeping the number of layers in the GUI design less complicated. One way I have done that is using only wxBoxSizers vertical/horizontal as needed, it tends to work fine (many layers also, but simpler).

But lately, I have started using wxAUI for these things. It looks better, it is easier to use and far more flexible with docking support etc. Generally drop a wxAuiManager into the main frame, and add panels to it.

Whether or not I use AUI, I tend to create custom panels (all the time using wxSmith) and add them to notebooks or AUI. I find that the application structure becomes cleaner (IMHO) that way.

So I think you have to prototype a layout until you find something that works. Test for every new complexity you add, so you are able to identify where problems begin.

Thanks for the advice I will try to convert the structure to a less complicated one, nevetherless I believe that there is a bug that should be fixed, I will try to follow your last hint in order to catch the point where the problem arise.

Giuseppe

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re:
« Reply #6 on: July 23, 2014, 10:44:16 pm »
Sorry, I just realised that I completely missed your answer with the sample....
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ