SDL: video: Set the ID of fullscreen modes when adding a display

From 98ae54ccc098e3ae19f7a41aec8c43cbefb8e094 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 1 Feb 2023 18:41:39 -0500
Subject: [PATCH] video: Set the ID of fullscreen modes when adding a display

When adding a display, traverse the list of added fullscreen modes and ensure the display ID is set to its final, valid value, or the modes added before calling SDL_AddVideoDisplay() will have an invalid display ID.
---
 src/video/SDL_video.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 8cfc66fcd459..25d08d314969 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -632,6 +632,7 @@ SDL_DisplayID SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send
 
     displays = (SDL_VideoDisplay *)SDL_realloc(_this->displays, (_this->num_displays + 1) * sizeof(*displays));
     if (displays) {
+        int i;
         _this->displays = displays;
         id = _this->next_object_id++;
         new_display = &displays[_this->num_displays++];
@@ -652,6 +653,10 @@ SDL_DisplayID SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send
         new_display->current_mode = &new_display->desktop_mode;
         SDL_FinalizeDisplayMode(&new_display->desktop_mode);
 
+        for (i = 0; i < new_display->num_fullscreen_modes; ++i) {
+            new_display->fullscreen_modes[i].displayID = id;
+        }
+
         if (send_event) {
             SDL_SendDisplayEvent(new_display, SDL_EVENT_DISPLAY_CONNECTED, 0);
         }