From b378bc5c83eab9abf6d025a1434d27c2a81fe912 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 12 Jul 2024 08:00:04 -0700 Subject: [PATCH] Make sure timers are initialized before any threads start This prevents race conditions and divide by zero if multiple threads start using the time functions simultaneously. --- src/thread/SDL_thread.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index 890ba2f7f5..5b5dae8fa3 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -27,6 +27,7 @@ #include "SDL_systhread.h" #include "SDL_hints.h" #include "../SDL_error_c.h" +#include "../timer/SDL_timer_c.h" /* The storage is local to the thread, but the IDs are global for the process */ @@ -371,6 +372,10 @@ SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *), SDL_InitTLSData(); +#ifndef SDL_TIMERS_DISABLED + SDL_TicksInit(); +#endif + /* Allocate memory for the thread info structure */ thread = (SDL_Thread *)SDL_calloc(1, sizeof(*thread)); if (!thread) {