wxTextEntryDialog and wxApp::OnExit 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
Game_Ender
Knows some wx things
Knows some wx things
Posts: 45
Joined: Wed Jun 15, 2005 5:47 pm

wxTextEntryDialog and wxApp::OnExit

Post by Game_Ender »

Is it possible to show a dialog from wxApp::OnExit. I am using wxMac 2.6.3 on Mac OS X and I get a crash on the ShowModal line of the snippet below. I don't see anything that says I shouldn't do be able to show dialogs and I am able to use the wxMessageDialog's fine from the OnInit() function, so I thought I would be able to do so in OnExit to.

Here is the backtrace:

Code: Select all

#0  0x7c000005 in ?? ()
#1  0x038c53ad in wxTimerBase::Notify (this=0x91cf770) at ../src/common/timercmn.cpp:61
#2  0x03824513 in wxProcessTimer (theTimer=0x91cf800, data=0x91cf770) at ../src/mac/carbon/timer.cpp:53
#3  0x92f3a8c2 in TimerVector ()
#4  0x90823bc9 in CFRunLoopRunSpecific ()
#5  0x90822eb5 in CFRunLoopRunInMode ()
#6  0x92f02b90 in RunCurrentEventLoopInMode ()
#7  0x92f021ce in ReceiveNextEventCommon ()
#8  0x93017b91 in ReceiveNextEvent ()
#9  0x037d62b4 in wxApp::MacDoOneEvent (this=0x9110370) at ../src/mac/carbon/app.cpp:1232
#10 0x037f5316 in wxDialog::DoShowModal (this=0x884b400) at ../src/mac/carbon/dialog.cpp:185
#11 0x037f53ab in wxDialog::Show (this=0x884b400, show=true) at ../src/mac/carbon/dialog.cpp:151
#12 0x037f568b in wxDialog::ShowModal (this=0x884b400) at ../src/mac/carbon/dialog.cpp:206
#13 0x000045ac in ssl::myApp::OnExit (this=0x9110370) at /path/to/my/project/dir/../src/myapp.cpp:145
Here is the contents of my OnExit method:

Code: Select all

int myApp::OnExit()
{
    wxTextEntryDialog* dlg = new 
        wxTextEntryDialog(NULL, 
                          wxT("Do you want save the config to the following"
                              "file?\nCurrent config will be overwritten"),
                          wxT(m_config->getFileName().c_str()));
                      
    if(dlg->ShowModal() == wxID_OK)
        m_config->saveToDisk();
    delete m_config;
    return wxApp::OnExit();
}
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Where is the delete dlg; to properly delete the dialog pointer?

Can't you also set the parent window? To the main frame for example?
Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi »

benedicte wrote:Where is the delete dlg; to properly delete the dialog pointer?

Can't you also set the parent window? To the main frame for example?
He should NOT delete it! He should call Destroy() on the wxTextEntryDialog object...

@Game_Ender: Your problem is that you need to turn off your wxTimer! I'm sure you have one running somewhere... Call the Stop() function...
Game_Ender
Knows some wx things
Knows some wx things
Posts: 45
Joined: Wed Jun 15, 2005 5:47 pm

Post by Game_Ender »

Thank you both, in my frame I had a timer that I didn't stop upon destruction of the object. It is odd that it did not cause any problems up to this point. After I made sure to properly stop the timer the dialog displayed fine.

I don't currently store the pointer to my main frame, but it would probably be a good idea to do so. It is still safe to use the main frame from OnExit, is it not?
Post Reply