Discussion:
Calling wxExecute() in an atexit() handler
'Ray Satiro' via wx-users
2014-08-22 06:13:41 UTC
Permalink
Hello I am updating some code for wxWidgets 3 and I am currently using master branch a307120 20140818. I have some code that restarts the application I am working on by calling in an atexit() handler wxExecute() with the executable path of the application on exit. You can see it here:https://github.com/jay/GalaXQL/blob/d36ed86/galaxql.cpp#L2103-2151

That works fine in both Windows and Linux, however I noticed an assert today in Ubuntu when I ran the app from the console:
../src/unix/utilsunx.cpp(1601): assert "static_cast<wxAppConsole*>(wxAppConsole::GetInstance())" failed in OnStart(): Ensure wxTheApp is set before calling wxExecute()

Indeed wxTheApp isn't set because I've already called wxTheApp->Exit() and that atexit handler is invoked after that. I wrote this code expecting that it would be safer to shut down wxWidgets resources (ie destroy wxTheApp) before relaunching the application. Is it safe to call wxExecute on exit after wxTheApp has shut down, and should I be concerned about that assertion?

Thanks
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-08-22 11:19:17 UTC
Permalink
On Thu, 21 Aug 2014 23:13:41 -0700 Ray Satiro wrote:

RS> Hello I am updating some code for wxWidgets 3 and I am currently
RS> using master branch a307120 20140818. I have some code that restarts
RS> the application I am working on by calling in an atexit() handler
RS> wxExecute() with the executable path of the application on exit. You
RS> can see it
RS> here:https://github.com/jay/GalaXQL/blob/d36ed86/galaxql.cpp#L2103-2151
RS>
RS> That works fine in both Windows and Linux, however I noticed an
RS> assert today in Ubuntu when I ran the app from the console:
RS> ../src/unix/utilsunx.cpp(1601): assert
RS> "static_cast<wxAppConsole*>(wxAppConsole::GetInstance())" failed in
RS> OnStart(): Ensure wxTheApp is set before calling wxExecute()
RS>
RS> Indeed wxTheApp isn't set because I've already called
RS> wxTheApp->Exit() and that atexit handler is invoked after that. I
RS> wrote this code expecting that it would be safer to shut down
RS> wxWidgets resources (ie destroy wxTheApp) before relaunching the
RS> application. Is it safe to call wxExecute on exit after wxTheApp has
RS> shut down, and should I be concerned about that assertion?

I strongly suspect it's not safe. Like most of non trivial wxWidgets
functionality, wxExecute() needs wxApp to exist. However you probably don't
use it in any non-trivial way, actually, so the best solution for you might
be to just replace it with a simple system() call.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
'Ray Satiro' via wx-users
2014-08-22 18:26:44 UTC
Permalink
Post by Vadim Zeitlin
RS> Hello I am updating some code for wxWidgets 3 and I am currently
RS> using master branch a307120 20140818. I have some code that restarts
RS> the application I am working on by calling in an atexit() handler
RS> wxExecute() with the executable path of the application on exit. You
RS> can see it
RS> here:https://github.com/jay/GalaXQL/blob/d36ed86/galaxql.cpp#L2103-2151
RS>
RS> That works fine in both Windows and Linux, however I noticed an
RS> ../src/unix/utilsunx.cpp(1601): assert
RS> "static_cast<wxAppConsole*>(wxAppConsole::GetInstance())" failed in
RS> OnStart(): Ensure wxTheApp is set before calling wxExecute()
RS>
RS> Indeed wxTheApp isn't set because I've already called
RS> wxTheApp->Exit() and that atexit handler is invoked after that. I
RS> wrote this code expecting that it would be safer to shut down
RS> wxWidgets resources (ie destroy wxTheApp) before relaunching the
RS> application. Is it safe to call wxExecute on exit after wxTheApp has
RS> shut down, and should I be concerned about that assertion?
I strongly suspect it's not safe. Like most of non trivial wxWidgets
functionality, wxExecute() needs wxApp to exist. However you probably don't
use it in any non-trivial way, actually, so the best solution for you might
be to just replace it with a simple system() call.
Thank you. I replaced wxExecute with execl.
https://github.com/jay/GalaXQL/commit/1a0198d
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...