wx terminate my program? core dump after calling SetMenuBar

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.
fluxy
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sun Nov 12, 2006 2:01 pm

wx terminate my program? core dump after calling SetMenuBar

Post by fluxy »

Hello,

i created my first wx Application yesterday, but there is a problem. There's no compiling or linking errors, but after calling SetMenuBar in the constructor of my TopLevelFrame class ( it's derived from wxFrame ) the programm will be terminated.

I've no idea that the reson could be. I have build the wx libs over the night again. With the static libs there are no problem to build. Here some additional hints for helping me: I am using the Debug libaries with unicode support. The Application is nothing more than a Hello World.

Thanks for Help.
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart »

Hi,

And what happens when you run your program in gdb? What does the backtrace tell you?

Regards,

David
fluxy
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sun Nov 12, 2006 2:01 pm

Post by fluxy »

Hey,

i am using Mircosoft Visual C++. But if i load the programm into the debugger, i tell me what i wrote. what's a backtrace?
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

fluxy wrote:Hey,

i am using Mircosoft Visual C++. But if i load the programm into the debugger, i tell me what i wrote. what's a backtrace?
I would highly suggest investing time to learn to use a debugger. Doing C++ without debugger is... not recommended.
fluxy
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sun Nov 12, 2006 2:01 pm

Post by fluxy »

I know how to use the debugger, i am sure. I think I not know that a backtrace is, because I am German. Maybe I only could not translate this word.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

fluxy wrote:I know how to use the debugger, i am sure. I think I not know that a backtrace is, because I am German. Maybe I only could not translate this word.
Google is your friend ;)
http://www.linux.com/howtos/Caudium-HOW ... race.shtml
fluxy
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sun Nov 12, 2006 2:01 pm

Post by fluxy »

Oh i see, you mean a function calling stack....

I can't show you that from the orginal project. But i created a new project, where i get the same problems. Here it is:
> foo.exe!wxStringData::IsValid() Zeile 249 + 0x28 Bytes C++
foo.exe!wxStringBase::operator=(const wxStringBase & stringSrc={...}) Zeile 775 + 0xf Bytes C++
foo.exe!wxString::operator=(const wxString & __that={...}) + 0x2f Bytes C++
foo.exe!wxWindowBase::SetName(const wxString & name={...}) Zeile 182 + 0x35 Bytes C++
foo.exe!wxStatusBar::Create(wxWindow * parent=0x00d74cf0, int id=1243816, long style=14109936, const wxString & name={...}) Zeile 71 + 0x13 Bytes C++
foo.exe!wxStatusBar::wxStatusBar(wxWindow * parent=0x00d74cf0, int id=1243816, long style=14109936, const wxString & name={...}) Zeile 28 C++
foo.exe!wxFrame::OnCreateStatusBar(int number=1243412, long style=14109936, int id=1243816, const wxString & name={...}) Zeile 341 + 0x35 Bytes C++
foo.exe!wxFrameBase::SetMenuBar(wxMenuBar * menubar=0x00d813e0) Zeile 565 + 0x12 Bytes C++
foo.exe!FooFrame::FooFrame(const wxString & title={...}, const wxPoint & pos={...}, const wxSize & size={...}) Zeile 24 C++
foo.exe!FooApp::OnInit() Zeile 10 + 0x7e Bytes C++
foo.exe!wxAppConsole::CallOnInit() Zeile 76 + 0x32 Bytes C++
foo.exe!wxEntryReal(int & argc=1, wchar_t * * argv=0x00d72a70) Zeile 424 + 0x1d Bytes C++
foo.exe!wxEntry(int & argc=1, wchar_t * * argv=0x00d72a70) Zeile 208 + 0xd Bytes C++
foo.exe!wxEntry(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * __formal=0x00000000, HINSTANCE__ * __formal=0x00000000, int nCmdShow=1) Zeile 385 + 0xd Bytes C++
foo.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00151efe, int nCmdShow=1) Zeile 5 + 0x33 Bytes C++
foo.exe!__tmainCRTStartup() Zeile 578 + 0x35 Bytes C
foo.exe!WinMainCRTStartup() Zeile 403 C
kernel32.dll!7c816fd7()
fluxy
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sun Nov 12, 2006 2:01 pm

Post by fluxy »

Here some new informations. The programm was compiled in unicode mode. That means that i am using the unicode libs of wx and I already compiled the project in unicode mode.

If I don't use the unicode libraries, there are another error. The linker could not find the information for one method of wx:

wxmsw28d_core.lib(appcmn.obj) : error LNK2001: unresolved external symbol "protected: virtual class wxString __thiscall wxAppTraitsBase::GetAssertStackTrace(void)" (?GetAssertStackTrace@wxAppTraitsBase@@MAE?AVwxString@@XZ)
D:\Source\foo\foo_ansi\foo.exe : fatal error LNK1120: 1 unresolved externals

Could anyone tell me whats going wrong on both cases?
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

For the unresolved symbol, you likely forgot to link against some lib.

As for the original bug... can you post source code? (a minimal working sample is often very helpful because we can try it)
fluxy
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sun Nov 12, 2006 2:01 pm

Post by fluxy »

sure. i will post all the code and project settings here.

I seperated header and source definitions, so there are at least 4 files i will post. The first ones are the header files.

Header of FooApp ( fooApp.h ):

Code: Select all

#ifndef FOO_APP_H
#define FOO_APP_H


class FooApp : public wxApp 
{
	public:
		virtual bool OnInit (void);
	private:
	protected:
		
};

#endif 
Then the header of the FooFrame class (fooFrame.h)

Code: Select all

#ifndef FOO_WIDGET_H  
#define FOO_WIDGET_H  
  
enum  
{  
    ID_QUIT = 1001,  
    ID_ABOUT = 1002,  
};  
  
class FooFrame : public wxFrame  
{  
	public:  
        FooFrame ( const wxString& title, const wxPoint& pos, const wxSize& size );  
        void OnQuit (wxCommandEvent& WXUNUSED(event));  
        void OnAbout (wxCommandEvent& WXUNUSED(event));  
    private:  
    protected:  
        DECLARE_EVENT_TABLE()  
};  
  
#endif 
Well, thats all classes I created myself. In the fooApp.cpp only the OnInit is implemented:

Code: Select all

#include "wx/wx.h"
#include "FooApp.h"
#include "FooFrame.h"

IMPLEMENT_APP ( FooApp )


bool FooApp::OnInit()
{
	FooFrame* pFoo = new FooFrame ( wxT ( "OrgaClient" ), wxPoint(50,50), wxSize(450,340));
	pFoo->Show ( TRUE );
	SetTopWindow ( pFoo );										
	return TRUE;
}
And the FooFrame implementation:

Code: Select all

#include "wx/wx.h"
#include "FooFrame.h"


BEGIN_EVENT_TABLE ( FooFrame, wxFrame )
	EVT_MENU ( ID_QUIT, FooFrame::OnQuit )
	EVT_MENU ( ID_ABOUT, FooFrame::OnAbout )
END_EVENT_TABLE ()


FooFrame::FooFrame ( const wxString& title, const wxPoint& pos, const wxSize& size ) 
					 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
	wxMenu *menuFile = new wxMenu;
    menuFile->Append( ID_ABOUT, wxT ("&About...") );
    menuFile->AppendSeparator();
    menuFile->Append( ID_QUIT, wxT ("E&xit") );
 
    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append( menuFile, wxT ("&File" ) );
 
    SetMenuBar( menuBar );

    CreateStatusBar();
    SetStatusText( wxT ("Welcome to wxWindows!") );
	
}


void FooFrame::OnQuit (wxCommandEvent& WXUNUSED(event))
{
	// At the moment there are no event handling
}

void FooFrame::OnAbout (wxCommandEvent& WXUNUSED(event))
{
	// At the moment there are no event handling
}

Some usefull project settings (posted from the vcproj-file)

Code: Select all

<Tool
				Name="VCCLCompilerTool"
				Optimization="0"
				AdditionalIncludeDirectories="E:\wx\lib\vc_lib\mswunivud"
				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;WINVER=0x0400;wxUSE_GUI=1;__WXDEBUG__"
				MinimalRebuild="true"
				BasicRuntimeChecks="3"
				RuntimeLibrary="3"
				UsePrecompiledHeader="0"
				WarningLevel="3"
				Detect64BitPortabilityProblems="false"
				DebugInformationFormat="4"
			/>
On Unicode Mode the libs which are included are
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib rpcrt4.lib winmm.lib advapi32.lib wsock32.lib wxpngd.lib wxzlibd.lib wxjpegd.lib wxtiffd.lib wxmsw28ud_core.lib wxbase28ud.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
On Ansi Mode it looks like this:
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib rpcrt4.lib winmm.lib advapi32.lib wsock32.lib wxpngd.lib wxzlibd.lib wxjpegd.lib wxtiffd.lib wxmsw28d_core.lib wxbase28d.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
Both configurations are build with CodeGeneration on Debug-Multithreaded Dll.

So I think thats all important informations about it.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Okay, it runs fine with my ANSI static non-debug wxMac libs. So it's either something with wxMSW or something in your configuration.

This is just a guess, but Unicode is often responsible for configuration problems. Can you try ANSI just to verify?

Also, several wxWidgets samples use menus. Can you see if these camples work?
fluxy
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sun Nov 12, 2006 2:01 pm

Post by fluxy »

I just tried it with the menu sample. There are 16 configurations regarding to this project, so i completed rebuild all of them. 15 configurations are build fine, but in the Debug configuration (not in the unicode debug) there are the same error i get in my non-unicode project:

Lining...
wxmsw28d_core.lib(appcmn.obj) : error LNK2001: unresolved external symbol "protected: virtual class wxString __thiscall wxAppTraitsBase::GetAssertStackTrace(void)" (?GetAssertStackTrace@wxAppTraitsBase@@MAE?AVwxString@@XZ)
vc_mswd\menu.exe : fatal error LNK1120: 1 unresolved externals

//edit: the configurations which are build (that means all excluding the one with the linker error) are working fine.... i am confused...
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

fluxy wrote:I just tried it with the menu sample. There are 16 configurations regarding to this project, so i completed rebuild all of them. 15 configurations are build fine, but in the Debug configuration (not in the unicode debug) there are the same error i get in my non-unicode project:

Lining...
wxmsw28d_core.lib(appcmn.obj) : error LNK2001: unresolved external symbol "protected: virtual class wxString __thiscall wxAppTraitsBase::GetAssertStackTrace(void)" (?GetAssertStackTrace@wxAppTraitsBase@@MAE?AVwxString@@XZ)
vc_mswd\menu.exe : fatal error LNK1120: 1 unresolved externals

//edit: the configurations which are build (that means all excluding the one with the linker error) are working fine.... i am confused...
Can you rephrase that? It doesn't sound to clear to me what you mean

Do yo umean you built 16 different configurations for the sample and all work but one?
fluxy
Earned a small fee
Earned a small fee
Posts: 15
Joined: Sun Nov 12, 2006 2:01 pm

Post by fluxy »

Yes, that's that i what to phrase. There are 16 configurations and 15 of them are build successfully. One other configuration, the debug ansi configuration, are not buld because of the linker error.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

fluxy wrote:that's that i what to phrase
that's what i want to phrase? ;)

Okay - i can't tell you exactly why this particular one fails, maybe someone else can help you. But... out the 15 configurations, not a single one suits your need?

After all, you don't absolutely need a debug version since you're not going to program wxWidgets itself

EDIT: But apart from building, do the menus work without crashing there? that's what i wanted to check in the first place when asking you to build the samples
Post Reply