Menu

#22 CTB - Avoid some bugs/warnings using timer class

open
nobody
None
5
2012-12-15
2008-02-28
No

I have 2 corrections about CTB - function "timer_fnc" file "Win32/timer.cpp":

1) For avoid crash during desctructor of a timer instance insert the line (the function timer_fnc can be called during destruction!)
I use the class 'timer' to start a routine. At the end routine I (re)start the timer ... recursively.
Everything is fine, but when I need to destroy the object may be a new call to timer_fnc although exitfnc no longer exists (at the moment there is no way to reset the pointer exitfnc after calling to stop().)

Solution:

/*new*/ if (tc->stop)
if(tc->exitfnc) tc->exitfnc(NULL);
if(tc->exitflag) *tc->exitflag = 1;

2) for avoid warnings insert following rows after return;
return;
/*new*/ wxUnusedVar( uTimerID ); // Here just to prevent compiler warnings
/*new*/ wxUnusedVar( uMsg ); // Here just to prevent compiler warnings
/*new*/ wxUnusedVar( dw1 ); // Here just to prevent compiler warnings
/*new*/ wxUnusedVar( dw2 ); // Here just to prevent compiler warnings
};

Then the new routine is:

static void WINAPI timer_fnc(UINT uTimerID,
UINT uMsg,
DWORD_PTR dwUser,
DWORD_PTR dw1,
DWORD_PTR dw2)
{
timer_control *tc = (timer_control*)dwUser;

if (tc->stop)
if(tc->exitfnc) tc->exitfnc(NULL);
if(tc->exitflag) *tc->exitflag = 1;
tc->stop = 0;
return;
wxUnusedVar( uTimerID ); // Here just to prevent compiler warnings
wxUnusedVar( uMsg ); // Here just to prevent compiler warnings
wxUnusedVar( dw1 ); // Here just to prevent compiler warnings
wxUnusedVar( dw2 ); // Here just to prevent compiler warnings
};

I hope that it can be useful

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.