Avoid data race in calls to VideoDriver::GetGameInterval
This commit is contained in:
@@ -27,15 +27,17 @@ bool _video_vsync; ///< Whether we should use vsync (only if active video driver
|
|||||||
|
|
||||||
void VideoDriver::GameLoop()
|
void VideoDriver::GameLoop()
|
||||||
{
|
{
|
||||||
this->next_game_tick += this->GetGameInterval();
|
|
||||||
|
|
||||||
/* Avoid next_game_tick getting behind more and more if it cannot keep up. */
|
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
if (this->next_game_tick < now - ALLOWED_DRIFT * this->GetGameInterval()) this->next_game_tick = now;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::recursive_mutex> lock(this->game_state_mutex);
|
std::lock_guard<std::recursive_mutex> lock(this->game_state_mutex);
|
||||||
|
|
||||||
|
const auto interval = this->GetGameInterval();
|
||||||
|
this->next_game_tick += interval;
|
||||||
|
|
||||||
|
/* Avoid next_game_tick getting behind more and more if it cannot keep up. */
|
||||||
|
if (this->next_game_tick < now - ALLOWED_DRIFT * interval) this->next_game_tick = now;
|
||||||
|
|
||||||
::GameLoop();
|
::GameLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user