Author Topic: WxSmith generate wrong code with sizer  (Read 11239 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: 9702
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: 538
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: 9702
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

Offline hermit

  • Single posting newcomer
  • *
  • Posts: 3
Re: WxSmith generate wrong code with sizer
« Reply #7 on: July 09, 2024, 03:16:30 pm »
Platform: Distributor ID:   Linuxmint
Description:   Linux Mint 21.3
Release:   21.3
Codename:   virginia

Codeblocks version 20.03

I am similar kind of issue while using wxSmith.

Code
    Panel1->SetSizer(StaticBoxSizer1);
    SetSizer(StaticBoxSizer1);
    Layout();
    BoxSizer1->Add(Panel1, 1, wxALL|wxEXPAND, 5);
    SetSizer(BoxSizer1);

it occurs when using StaticBoxSizer. wxFrame > wxBoxSizer > wxPanel:Panel1> wxStaticBoxSizer > wxButton1 wxButton2 ...

Then it generates
Code
 SetSizer(StaticBoxSizer1);
after commenting SetSizer the code works well

Is there is something i am missing?

Thanks in advance

Regards,
Hermit
« Last Edit: July 09, 2024, 03:18:43 pm by hermit »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1631
Re: WxSmith generate wrong code with sizer
« Reply #8 on: July 09, 2024, 03:48:15 pm »
IIRC this issue was fixed about a year ago. Current trunk generates this code:
Code
    wxBoxSizer* BoxSizer1;
    wxStaticBoxSizer* StaticBoxSizer1;

    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxDefaultSize);
    Move(wxDefaultPosition);
    BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
    Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, _("Label"));
    Button1 = new wxButton(Panel1, ID_BUTTON1, _("Label"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
    StaticBoxSizer1->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Button2 = new wxButton(Panel1, ID_BUTTON2, _("Label"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
    StaticBoxSizer1->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel1->SetSizer(StaticBoxSizer1);
    BoxSizer1->Add(Panel1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    SetSizer(BoxSizer1);
    BoxSizer1->SetSizeHints(this);

It runs OK on MSW with wxWidgets 3.2.5

Offline hermit

  • Single posting newcomer
  • *
  • Posts: 3
Re: WxSmith generate wrong code with sizer
« Reply #9 on: July 10, 2024, 10:21:48 am »
Hi,
I was using wxWidgets 3.2.4
Could you please help me out what am i doing wrong?

i build the wxwidgets from the source but i couldnt find 3.2.5.

after your suggestion i tried again to install wxWidgets as per the instructions but i could find only wxwidgets 3.2.4.
I used this link:-
Code
https://docs.codelite.org/wxWidgets/repo32/
here is my wxWidgets version :-
Code
wxWidgets-3.2.4/gtk-build/wx-config --version
3.2.4

Here is my Build log

Code
Checking for existence: /home/gunjan/wxWidgets-3.2.4/gtk-build/samples/gunjansample/test_hello/bin/Debug/test_hello
Set variable: LD_LIBRARY_PATH=.:/usr/lib/x86_64-linux-gnu:
Executing: /home/gunjan/wxWidgets-3.2.4/gtk-build/samples/gunjansample/test_hello/bin/Debug/test_hello  (in /home/gunjan/wxWidgets-3.2.4/gtk-build/samples/gunjansample/test_hello/.)
Process terminated with status -11 (0 minute(s), 0 second(s))


i am still getting the same error here i created small application. At Line 74 you can see SetSizer(StaticBoxSizer1);
Code
#include "test_helloMain.h"
#include <wx/msgdlg.h>
#include <wx/log.h> // Include wxLog for debugging

//(*InternalHeaders(test_helloFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(test_helloFrame)
const long test_helloFrame::ID_BUTTON1 = wxNewId();
const long test_helloFrame::ID_TEXTCTRL1 = wxNewId();
const long test_helloFrame::ID_PANEL1 = wxNewId();
const long test_helloFrame::idMenuQuit = wxNewId();
const long test_helloFrame::idMenuAbout = wxNewId();
const long test_helloFrame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(test_helloFrame,wxFrame)
    //(*EventTable(test_helloFrame)
    //*)
END_EVENT_TABLE()

test_helloFrame::test_helloFrame(wxWindow* parent,wxWindowID id)
{
    wxLogDebug("test_helloFrame Constructor - Start");
    //(*Initialize(test_helloFrame)
    wxBoxSizer* BoxSizer1;
    wxMenu* Menu1;
    wxMenu* Menu2;
    wxMenuBar* MenuBar1;
    wxMenuItem* MenuItem1;
    wxMenuItem* MenuItem2;
    wxStaticBoxSizer* StaticBoxSizer1;

    Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
    BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
    Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxSize(185,134), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, _("Label"));
    Button1 = new wxButton(Panel1, ID_BUTTON1, _("Label"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
    StaticBoxSizer1->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    TextCtrl1 = new wxTextCtrl(Panel1, ID_TEXTCTRL1, _("Text"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    StaticBoxSizer1->Add(TextCtrl1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel1->SetSizer(StaticBoxSizer1);
    SetSizer(StaticBoxSizer1);
    Layout();
    BoxSizer1->Add(Panel1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    SetSizer(BoxSizer1);
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);
    BoxSizer1->Fit(this);
    BoxSizer1->SetSizeHints(this);

    Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&test_helloFrame::OnButton1Click);
    Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&test_helloFrame::OnTextCtrl1Text);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&test_helloFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&test_helloFrame::OnAbout);
    //*)
    wxLogDebug("test_helloFrame Constructor - End");
}

test_helloFrame::~test_helloFrame()
{
    wxLogDebug("test_helloFrame Destructor");
    //(*Destroy(test_helloFrame)
    //*)
}

void test_helloFrame::OnQuit(wxCommandEvent& event)
{
    wxLogDebug("OnQuit");
    Close();
}

void test_helloFrame::OnAbout(wxCommandEvent& event)
{
    wxLogDebug("OnAbout");
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void test_helloFrame::OnButton1Click(wxCommandEvent& event)
{
    wxLogDebug("OnButton1Click");
    wxMessageBox(_("Button clicked"), _("Info"));
}

void test_helloFrame::OnTextCtrl1Text(wxCommandEvent& event)
{
    wxLogDebug("OnTextCtrl1Text");
}





Any help or suggestion or workaround is highly appreciated.
Thanks

Regards,
Hermit
« Last Edit: July 10, 2024, 10:28:50 am by hermit »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1631
Re: WxSmith generate wrong code with sizer
« Reply #10 on: July 10, 2024, 11:15:09 am »
You must update CB, if Mint does not allow so you must use a nightly or compile the source.