If OnInit fails, program crashes Topic is solved

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.
Post Reply
rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

If OnInit fails, program crashes

Post by rodrigod »

On my program I test if it is already open and if it is, OnInit() returns false and was suposed to close the aplication. But instead it crashes.

Debuging I saw that it crashes after it returns false it crashes when the function wxEntryCleanup calls delete app.

I have no idea what the problems is. Is there any clue of what could cause this

thanks
spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum »

hi rodrigod,

mm yes, is right, returning flase the application should terminate.

I think that if you have a small code snippets and the call stack trace we can help you.

greetings
spectrum
rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

Post by rodrigod »

Here it is

Code: Select all

DECLARE_APP(CSPPCOMMApp)
IMPLEMENT_APP(CSPPCOMMApp)

CSPPCOMMApp::CSPPCOMMApp() : wxApp()
{
} 


bool CSPPCOMMApp::OnInit()
{
if (ProcessActive("SPPCOMFG.EXE") != 0 )
{
     ErrMessage(IDS_APLIC_DISP,1,"");
     return false;
}
}
header

Code: Select all

class CSPPCOMMApp : public wxApp
{
public:
	CSPPCOMMApp();

	virtual bool OnInit();
	virtual int OnExit();

};
This is about it. Any ideas?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

Code: Select all

CSPPCOMMApp::CSPPCOMMApp() : wxApp()
{
}
you're not supposed to have a ctor for this. That happens in the IMPLEMENT_APP macro.
Use the source, Luke!
rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

Post by rodrigod »

I removed it and the error continued.

It is a heap problem. It happens when wx tries to delete the application class in the following function.

Code: Select all

void wxEntryCleanup()
{
    DoCommonPreCleanup();


    // delete the application object
    if ( wxTheApp )
    {
        wxTheApp->CleanUp();

        // reset the global pointer to it to NULL before destroying it as in
        // some circumstances this can result in executing the code using
        // wxTheApp and using half-destroyed object is no good
        wxAppConsole * const app = wxApp::GetInstance();
        wxApp::SetInstance(NULL);
        delete app;
    }


    DoCommonPostCleanup();
}
Everything goes fine until delete app, and in the debug I saw that app is pointing to the correct class. So what could be the problem???

thanks
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

did you remove the default ctor from the class declaration, too?

Can you post a minimal complete sample that creates the error?

There is something wrong with the application object and i think this might also be the problem in your other thread "Unexpected Parameter".
Use the source, Luke!
rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

Post by rodrigod »

Thanks for the help,
when trying to reproduce the error in another file I found what the problem was. I am porting from mfc. and in mfc there is no DECLARE_APP(AppClass) macro, it is used like a class:
AppClass theApp;
And this line caused the error.
however the Unexpected error still occours
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Well is it fixed or not? :? When you say you still get the 'Unexpected error', that's not very precise, since most errors are unexpected ;)
rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

Post by rodrigod »

oops I wrote it wrong. I meant the error Unexpected Parameter still occours
Post Reply