Hi
I'm currently try to find the source of a bug in a 3rd party library. The library perform scientific plotting and includes code to run interactive plots from a command-line application using wxWidgets.
We are having some issues when doing the following:
1) Send plot commands to the library,
2) Tell it to display the plot (library calls wxInitialize()), plot is displayed in a wxFrame.
3) Closing the wxFrame returns program flow to the user's code after calling wxUninitialize().
4) repeat 1-3
On Windows this works fine, but on Linux attempting to create a second window causes a segfault. This seems to occur when we create the eventloop. Is there anything fundamental that stops us initializing, uninitializing then reinitializing wxWidgets on Linix or are we just doing something wrong in the way we are doing this? If I remove the call to wxUninitialize() then everything runs fine, but presumably not calling wxUninitiailize ever will lead to a memory leak on exit.
Thanks in advance for any pointers
Phil
multiple calls to wxInitialize/wxUninitialize
-
- Knows some wx things
- Posts: 40
- Joined: Mon Jun 09, 2008 9:59 pm
-
- Knows some wx things
- Posts: 39
- Joined: Sun Oct 10, 2010 1:02 am
Re: multiple calls to wxInitialize/wxUninitialize
I think the problem does not come from wxInitialize. You can create a simple library just display a wxFrame and after exit return to program flow to make sure where the problem come from.wxInitialize
This function is used in wxBase only and only if you don't create wxApp object at all.
In this case you must call it from your main() function before calling any other wxWidgets functions.
If the function returns false the initialization could not be performed, in this case the library cannot be used and wxUninitialize() shouldn't be called neither.
This function may be called several times but wxUninitialize() must be called for each successful call to this function.
Or you can try to create a library following the bottom guide of this link: http://wiki.wxwidgets.org/Creating_A_DL ... pplication. Check out this part: "Creating a wxWidgets DLL application with wxWidgets 2.8.9, with GUI support ".