Call to SetMenuBar() Results in Segmentation Fault

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Call to SetMenuBar() Results in Segmentation Fault

Post by spflanze »

In this wxWidgets genertated code snippet:

Code: Select all

    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);
The last line, which is "SetMenuBar(MenuBar1)", triggers a segmentation fault. It does not allow me to step into this function.

The debug output:
Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\Engineering Software\TIA Designer\
Adding source dir: C:\Engineering Software\TIA Designer\
Adding file: C:\Engineering Software\TIA Designer\bin\Debug\TIA Designer.exe
Changing directory to: C:/ENGINE~1/TIADES~2/.
Set variable: PATH=.;C:\wxWidgets-3.0.3\lib\gcc_dll;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW
Starting debugger: C:\Program Files (x86)\CodeBlocks\MINGW\bin\gdb.exe -nx -fullname -quiet -args C:/ENGINE~1/TIADES~2/bin/Debug/TIADES~1.EXE
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.6.1
Child process PID: 6748
At C:\Engineering Software\TIA Designer\TIA_DesignerMain.cpp:524
Continuing...
Program received signal SIGSEGV, Segmentation fault.
In wxWindowBase::Layout() () (C:\wxWidgets-3.0.3\lib\gcc_dll\wxmsw30u_gcc_custom.dll)
The Call Stack:
#0 0x6a65325d wxWindowBase::Layout() () (C:\wxWidgets-3.0.3\lib\gcc_dll\wxmsw30u_gcc_custom.dll:??)
#1 0x75746e57 USER32!GetThreadDesktop() (C:\Windows\syswow64\user32.dll:??)
#2 0x28b7f4 ?? () (??:??)
#3 0x3b8000c ?? () (??:??)
Please tell me what I need to do next to solve this problem.
Last edited by spflanze on Thu Mar 22, 2018 11:23 pm, edited 1 time in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Call to SetMenuBar() Resutls in Segmentation Fault

Post by doublemax »

Works fine for me when i paste this into the "minimal" sample.

The problem must lie somewhere else.
Use the source, Luke!
Nunki
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Fri Sep 14, 2012 8:26 am
Location: Kontich, Belgium
Contact:

Re: Call to SetMenuBar() Resutls in Segmentation Fault

Post by Nunki »

Hi Spflanze,

Just a thought, since I cannot make that conclusion from your code snippet.

I use a base class of type wxMDIParentFrame, does not really matter what, this is the basic frame to which I want to link my menu.

Code: Select all

class tcBaseFrame: public wxMDIParentFrame
After creation of this frame, I call my method to make a menubar, and by calling this->SetMenuBar the menu is linked to tcBaseFrame.

Code: Select all

void tcBaseFrame::MkMenu(void)
{
...
 rApp.hMnu = new wxMenuBar();
 rApp.hMnu->Append(hMnuBestand,wxT("Bestand"));
 this->SetMenuBar(rApp.hMnu);
 ...
Now do you have such link too ? Or do you call SetMenuBar from out of the blue. I would think in that case wxWidgets might think youo want to set the menubar of your basic dektop, which may not be allowed.

Hope this helps you out.
Regards,
Nunki
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by spflanze »

SetMenuBar() is called within the frame's constructor. The frame is an instantiation of a class which is derived from wxFrame.

I not sure what was meant by "link". The frame object's self pointer keyword "this" is not used.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by doublemax »

There is nothing wrong with the code you posted, the problem must be somewhere else. As SetMenuBar also initiates a Layout() and that's the one that crashes, there might be a problem with the sizer code.

Can you show the whole constructor?
Use the source, Luke!
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by spflanze »

I removed the menu with the intent to put it back later, to cover the possibility it was due to wxs file corruption. One removed the sigmentation fault happened on the call that initializes the status bar. So I removed the stats bar.

Now the segmentation fault happens on the call to Layout(). I am not able to step into this function. Now I wonder if there is corruption involving a sizer.
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by spflanze »

I did more deletions to bring the development back to an earlier point where the program did run successfully. And then I moved forward to a point where the segmentation fault happened again. In this way I have narrowed down the cause.

The project can be downloaded from:
http://www.mediafire.com/file/69eyh6gy6 ... signer.zip

In the D1 tab there is a wxBoxSizer type object named D1TabBoxSizer. When its Orientation property is set to wxHORIZONTAL the segmentation fault happens. When it is set to wxVERTICAL it does not, and the program runs. Could this be a bug in Layout() ?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by doublemax »

Code: Select all

    D1TabBoxSizer = new wxBoxSizer(wxHORIZONTAL);
    D1TabPanel->SetSizer(D1TabBoxSizer);
    SetSizer(D1TabBoxSizer);
    Layout();
The same sizer is set to two different windows, that can't be right.

I remember to have seen this before, wxSmith creates this wrong code sometimes. But i don't know what to do about it.
Use the source, Luke!
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by eranon »

I read diagonally, but maybe cousin of this topic on August 2017 (about excess of SetSizer and Layout as doublemax pointed): http://forums.codeblocks.org/index.php?topic=22068.0. So, maybe you should report the issue towards the Code::Blocks team (who maintains wxSmith)...
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by doublemax »

Thanks eranon for finding this.

The post seems to hint to a solution, which would be to check "default size" for D1TabPanel.
Use the source, Luke!
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by spflanze »

For D1TabPanel I have the checkbox for "Default Min Size" and "Default Max Size" already checked. They were, and are, checked when the segmentation fault happened. So is there another workaround?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by doublemax »

Is there also a checkbox for "default size"?

In the generated code there is still a size given:

Code: Select all

D1TabPanel = new wxPanel(NotebookPartData, ID_D1TabPanel, wxPoint(113,13), wxSize(676,30), wxTAB_TRAVERSAL, _T("ID_D1TabPanel"));
Use the source, Luke!
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by spflanze »

I have been using wxWidgets 3.03 . Version 3.04 has recently come out. I want to find out if this bug is fixed in that version. I know where the wxWidgets version is specified when a project is created. But can this be changed in an already created project?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by doublemax »

This is not a bug in wxWidgets, just in wxSmith.
Use the source, Luke!
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Re: Call to SetMenuBar() Results in Segmentation Fault

Post by spflanze »

I found the default size checkbox. I have checked it for all tabs in the wxNotebook front panel object. But the segmentation fault persists.
Post Reply