In svn trunk it is no longer possible to use a static wxTimer. The attached diff to the 'combo' sample demonstrates this. It will compile OK, but at runtime static initialisation calls wxTimer::Init before wxApp is created. As a result, the line (src/common/timercmn.cpp:57): wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; leaves traits NULL, which leads to the fatal assert: wxFAIL_MSG( _T("No timer implementation for this platform") ); I can't see an easy fix for this, without reverting the use of wxAppTraits to determine the platform
Asked
Active
Viewed 73 times
-1
-
What is your question? Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please take the [tour] and read about [ask] good questions. Lastly please read [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Sep 17 '21 at 05:21
-
And this seems like it would be better handled by creating an issue for the wx project rather than posting a (non) question here. – Some programmer dude Sep 17 '21 at 05:22
-
@sri12345, please create a ticket at track.wxwidgets.org. Mention, platform, attach the reproduce and also mention when it was possible last. However, keep in mind that using global static variables is not good idea - library has to be initialized first and this is done with wrapping. You need to fix your code whatever it did. – Igor Sep 17 '21 at 13:19
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 24 '21 at 08:17
2 Answers
1
You could never create any non-trivial wx objects before the GUI initialization. I wasn't even aware that creating a static wxTimer ever worked, but if it did, it must have been a very, very long time ago.
The minimal fix is probably to replace your object with a function returning wxTimer& and allocating the timer on demand when it is called.
VZ.
- 20,185
- 3
- 37
- 40
-
-
Yes, exactly (you should probably copy this code to your own answer to this question). – VZ. Oct 03 '21 at 19:50
0
As explained in the other answer, construction of wxTimer should happen after initialization of the GUI. To enforce that, you can use a function that initializes a static variable first time it's called:
#include <wx/timer.h>
wxTimer& staticWxTimer() {
static wxTimer timer{};
return timer;
}
As explained here, this object will be initialized exactly once - the first time control passes through its declaration.
Ayxan Haqverdili
- 23,309
- 5
- 37
- 74