SDL: haiku: fix modelist double-free

From e14514f484f92487e17f4b91d1d6cb28458071e0 Mon Sep 17 00:00:00 2001
From: erysdren <[EMAIL REDACTED]>
Date: Wed, 7 Jan 2026 00:54:18 -0600
Subject: [PATCH] haiku: fix modelist double-free

---
 src/video/haiku/SDL_bmodes.cc | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/video/haiku/SDL_bmodes.cc b/src/video/haiku/SDL_bmodes.cc
index 70bd9020f888d..d589efe8a4001 100644
--- a/src/video/haiku/SDL_bmodes.cc
+++ b/src/video/haiku/SDL_bmodes.cc
@@ -244,17 +244,17 @@ void HAIKU_GetDisplayModes(_THIS, SDL_VideoDisplay *display) {
     uint32 count, i;
     
     /* Get graphics-hardware supported modes */
-    bscreen.GetModeList(&bmodes, &count);
-    bscreen.GetMode(&this_bmode);
-    
-    for (i = 0; i < count; ++i) {
-        // FIXME: Apparently there are errors with colorspace changes
-        if (bmodes[i].space == this_bmode.space) {
-            _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
-            SDL_AddDisplayMode(display, &mode);
+    if (bscreen.GetModeList(&bmodes, &count) == B_OK && bscreen.GetMode(&this_bmode) == B_OK)
+    {
+        for (i = 0; i < count; ++i) {
+            // FIXME: Apparently there are errors with colorspace changes
+            if (bmodes[i].space == this_bmode.space) {
+                _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
+                SDL_AddDisplayMode(display, &mode);
+            }
         }
+        free(bmodes); /* This should not be SDL_free() */
     }
-    free(bmodes); /* This should not be SDL_free() */
 }