Author Topic: wxSmith bad code generation  (Read 2843 times)

Offline 4ian

  • Single posting newcomer
  • *
  • Posts: 5
    • Compil Games
wxSmith bad code generation
« on: June 24, 2012, 11:54:48 pm »
Hi,

Since I've updated Code::Blocks to the latest revision ( 8059 ), wxSmith is generating code for my window which lead to crash when the window is created at runtime ( i.e, a crash in the window constructor ).
Here is the code generated by revision 7789: ( Works fine )

Code: [Select]
EditPropJeu::EditPropJeu( wxWindow* parent, Game & game_ ) :
    game(game_)
{
    //(*Initialize(EditPropJeu)
    wxFlexGridSizer* FlexGridSizer4;
    wxFlexGridSizer* FlexGridSizer19;
    wxFlexGridSizer* FlexGridSizer3;
    wxFlexGridSizer* FlexGridSizer5;
    wxFlexGridSizer* FlexGridSizer2;
    wxFlexGridSizer* FlexGridSizer29;
    wxFlexGridSizer* FlexGridSizer18;
    wxFlexGridSizer* FlexGridSizer20;
    wxFlexGridSizer* FlexGridSizer12;
    wxFlexGridSizer* FlexGridSizer6;
    wxFlexGridSizer* FlexGridSizer1;
    wxFlexGridSizer* FlexGridSizer17;

    Create(parent, wxID_ANY, _("Editer les propriétés du jeu"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER, _T("wxID_ANY"));
    FlexGridSizer1 = new wxFlexGridSizer(0, 1, 0, 0);
    FlexGridSizer1->AddGrowableCol(0);
    FlexGridSizer1->AddGrowableRow(2);
    FlexGridSizer17 = new wxFlexGridSizer(0, 3, 0, 0);
    Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxSize(420,54), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    Panel1->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
    FlexGridSizer18 = new wxFlexGridSizer(0, 3, 0, 0);
    StaticBitmap5 = new wxStaticBitmap(Panel1, ID_STATICBITMAP5, wxBitmap(wxImage(_T("res/paraJeu.png"))), wxDefaultPosition, wxDefaultSize, wxNO_BORDER, _T("ID_STATICBITMAP5"));
    FlexGridSizer18->Add(StaticBitmap5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText6 = new wxStaticText(Panel1, ID_STATICTEXT6, _("Vous pouvez régler les principaux paramètres de votre jeu,\nainsi que les écrans annexes, comme celui du chargement."), wxDefaultPosition, wxSize(371,32), 0, _T("ID_STATICTEXT6"));
    FlexGridSizer18->Add(StaticText6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel1->SetSizer(FlexGridSizer18);
    FlexGridSizer18->SetSizeHints(Panel1);
    FlexGridSizer17->Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    FlexGridSizer1->Add(FlexGridSizer17, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    StaticLine1 = new wxStaticLine(this, ID_STATICLINE1, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE1"));
    FlexGridSizer1->Add(StaticLine1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    Notebook1 = new wxNotebook(this, ID_NOTEBOOK1, wxDefaultPosition, wxDefaultSize, 0, _T("ID_NOTEBOOK1"));
    Panel2 = new wxPanel(Notebook1, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL2"));
//...

And here is the code generated by the revision-which-is-trying-to-kill-my-application :

Code: [Select]
EditPropJeu::EditPropJeu( wxWindow* parent, Game & game_ ) :
    game(game_)
{
    //(*Initialize(EditPropJeu)
    wxFlexGridSizer* FlexGridSizer4;
    wxFlexGridSizer* FlexGridSizer19;
    wxFlexGridSizer* FlexGridSizer3;
    wxFlexGridSizer* FlexGridSizer5;
    wxFlexGridSizer* FlexGridSizer2;
    wxFlexGridSizer* FlexGridSizer29;
    wxFlexGridSizer* FlexGridSizer18;
    wxFlexGridSizer* FlexGridSizer20;
    wxFlexGridSizer* FlexGridSizer12;
    wxFlexGridSizer* FlexGridSizer6;
    wxFlexGridSizer* FlexGridSizer1;
    wxFlexGridSizer* FlexGridSizer17;

    Create(parent, wxID_ANY, _("Editer les propriétés du jeu"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER, _T("wxID_ANY"));
    FlexGridSizer1 = new wxFlexGridSizer(0, 1, 0, 0);
    FlexGridSizer1->AddGrowableCol(0);
    FlexGridSizer1->AddGrowableRow(2);
    FlexGridSizer17 = new wxFlexGridSizer(0, 3, 0, 0);
    Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxSize(420,54), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    Panel1->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
    FlexGridSizer18 = new wxFlexGridSizer(0, 3, 0, 0);
    StaticBitmap5 = new wxStaticBitmap(Panel1, ID_STATICBITMAP5, wxBitmap(wxImage(_T("res/paraJeu.png"))), wxDefaultPosition, wxDefaultSize, wxNO_BORDER, _T("ID_STATICBITMAP5"));
    FlexGridSizer18->Add(StaticBitmap5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText6 = new wxStaticText(Panel1, ID_STATICTEXT6, _("Vous pouvez régler les principaux paramètres de votre jeu,\nainsi que les écrans annexes, comme celui du chargement."), wxDefaultPosition, wxSize(371,32), 0, _T("ID_STATICTEXT6"));
    FlexGridSizer18->Add(StaticText6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel1->SetSizer(FlexGridSizer18);
    SetSizer(FlexGridSizer18);
    Layout();
    FlexGridSizer17->Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    FlexGridSizer1->Add(FlexGridSizer17, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    StaticLine1 = new wxStaticLine(this, ID_STATICLINE1, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE1"));
    FlexGridSizer1->Add(StaticLine1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    Notebook1 = new wxNotebook(this, ID_NOTEBOOK1, wxDefaultPosition, wxDefaultSize, 0, _T("ID_NOTEBOOK1"));
    Panel2 = new wxPanel(Notebook1, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL2"));

The latest revision added two lines which seem to be not appropriate :
Code: [Select]
   SetSizer(FlexGridSizer18);
    Layout();

I've attached the associated wxSmith file if needed.
4ian

Game Develop : Free game development software

Offline 4ian

  • Single posting newcomer
  • *
  • Posts: 5
    • Compil Games
Re: wxSmith bad code generation
« Reply #1 on: June 28, 2012, 02:42:22 pm »
Any ideas ? :)
I cannot use the latest version of Code::Blocks due to this issue.  :-\
4ian

Game Develop : Free game development software

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: wxSmith bad code generation
« Reply #2 on: June 28, 2012, 08:44:25 pm »
Well I can confirm it does crash because of the new "SetSizer(FlexGridSizer18);" line. Although I don't know why, the code looks like it should be fine...

I noticed that the wx2.9 docs mention that the SetSizer() function will be depreciated and that you should use AssignSizer(), instead. So maybe it's a wx2.9 quirk?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9496
Re: wxSmith bad code generation
« Reply #3 on: June 29, 2012, 07:33:59 am »
Your app doesn't crash because of that, but because you set a non-default size for the top panel "Panel1". Such things you should never do if you are not very, very sure you need to as this screws the sizers principle completely.

If you really need a minimal size, use "Default min size".

Not a Code::Blocks/wxSmith issue, locking topic therefore.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ