Procházet zdrojové kódy

Fixed crash if a display is enumerated twice

This can happen if a monitor is in the process of becoming primary because another monitor was disconnected.

(cherry picked from commit 07578fde3dad2dadd605f5b18399c8d021f6ae5d)
(cherry picked from commit 2468fccf7fa7fa315d6652c7babf85f2d09f035b)
Sam Lantinga před 1 rokem
rodič
revize
02be870c54
1 změnil soubory, kde provedl 10 přidání a 1 odebrání
  1. 10 1
      src/video/windows/SDL_windowsmodes.c

+ 10 - 1
src/video/windows/SDL_windowsmodes.c

@@ -318,10 +318,19 @@ static void WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info,
         if (SDL_wcscmp(driverdata->DeviceName, info->szDevice) == 0) {
             SDL_bool moved = (index != i);
 
+            if (driverdata->state != DisplayRemoved) {
+                /* We've already enumerated this display, don't move it */
+                return;
+            }
+
+            if (index >= _this->num_displays) {
+                /* This should never happen due to the check above, but just in case... */
+                return;
+            }
+
             if (moved) {
                 SDL_VideoDisplay tmp;
 
-                SDL_assert(index < _this->num_displays);
                 SDL_memcpy(&tmp, &_this->displays[index], sizeof(tmp));
                 SDL_memcpy(&_this->displays[index], &_this->displays[i], sizeof(tmp));
                 SDL_memcpy(&_this->displays[i], &tmp, sizeof(tmp));