SDL: video: Explicitly disallow setting the parent of a window to itself

From ca9b7c8ea33488f62eff6787eec433aa78f2a9ca Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 18 Jun 2025 09:21:09 -0400
Subject: [PATCH] video: Explicitly disallow setting the parent of a window to
 itself

Doing so causes a cycle in the window hierarchy tree graph, which leads to infinite recursion when destroying the windows.
---
 src/video/SDL_video.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index a1b1bba1c5213..d42ecd492a244 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -3672,6 +3672,10 @@ bool SDL_SetWindowParent(SDL_Window *window, SDL_Window *parent)
         CHECK_WINDOW_NOT_POPUP(parent, false);
     }
 
+    if (window == parent) {
+        return SDL_SetError("Cannot set the parent of a window to itself.");
+    }
+
     if (!_this->SetWindowParent) {
         return SDL_Unsupported();
     }