BACKENDS: Attempt to address race condition on slow systems with timers

This commit is contained in:
Eugene Sandulenko 2020-07-02 18:04:54 +02:00
parent 05b6bb2021
commit 698dbbdfca

View file

@ -29,7 +29,12 @@
#include "common/textconsole.h"
static bool timerInstalled = false;
static Uint32 timer_handler(Uint32 interval, void *param) {
if (!timerInstalled)
return interval;
((DefaultTimerManager *)param)->handler();
return interval;
}
@ -40,11 +45,14 @@ SdlTimerManager::SdlTimerManager() {
error("Could not initialize SDL: %s", SDL_GetError());
}
timerInstalled = true;
// Creates the timer callback
_timerID = SDL_AddTimer(10, &timer_handler, this);
}
SdlTimerManager::~SdlTimerManager() {
timerInstalled = false;
// Removes the timer callback
SDL_RemoveTimer(_timerID);
}