Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: gst0098 on June 25, 2014, 01:24:39 pm

Title: WxSmith generate wrong code with sizer
Post by: gst0098 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
Title: Re:
Post by: MortenMacFly 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...
Title: Re:
Post by: gst0098 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
Title: Re:
Post by: gst0098 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
Title: Re:
Post by: cacb 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.
Title: Re:
Post by: gst0098 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
Title: Re:
Post by: MortenMacFly on July 23, 2014, 10:44:16 pm
Sorry, I just realised that I completely missed your answer with the sample....