Browse Source

Fixed warning C28159: Consider using 'GetTickCount64' instead of 'GetTickCount'. Reason: GetTickCount overflows roughly every 49 days. Code that does not take that into account can loop indefinitely. GetTickCount64 operates on 64 bit values and does not have that problem

Sam Lantinga 1 year ago
parent
commit
a9b87ee201
2 changed files with 14 additions and 0 deletions
  1. 7 0
      src/video/windows/SDL_windowsevents.c
  2. 7 0
      src/video/windows/SDL_windowsmouse.c

+ 7 - 0
src/video/windows/SDL_windowsevents.c

@@ -1643,7 +1643,14 @@ void WIN_SendWakeupEvent(SDL_VideoDevice *_this, SDL_Window *window)
 void WIN_PumpEvents(SDL_VideoDevice *_this)
 {
     MSG msg;
+#ifdef _MSC_VER /* We explicitly want to use GetTickCount(), not GetTickCount64() */
+#pragma warning(push)
+#pragma warning(disable : 28159)
+#endif
     DWORD end_ticks = GetTickCount() + 1;
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
     int new_messages = 0;
 #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
     const Uint8 *keystate;

+ 7 - 0
src/video/windows/SDL_windowsmouse.c

@@ -316,10 +316,17 @@ void WIN_SetCursorPos(int x, int y)
     SetCursorPos(x, y);
 
     /* Flush any mouse motion prior to or associated with this warp */
+#ifdef _MSC_VER /* We explicitly want to use GetTickCount(), not GetTickCount64() */
+#pragma warning(push)
+#pragma warning(disable : 28159)
+#endif
     SDL_last_warp_time = GetTickCount();
     if (!SDL_last_warp_time) {
         SDL_last_warp_time = 1;
     }
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
 }
 
 static int WIN_WarpMouse(SDL_Window *window, float x, float y)