changeset 3521:76f9b76ddf0f

Don't add any renderers if you can't add any displays
author Sam Lantinga <slouken@libsdl.org>
date Fri, 04 Dec 2009 09:01:48 +0000
parents 83518f8fcd61
children fa1abe1ff8b8
files src/video/win32/SDL_win32modes.c src/video/win32/SDL_win32modes.h src/video/win32/SDL_win32video.c src/video/x11/SDL_x11modes.c src/video/x11/SDL_x11modes.h src/video/x11/SDL_x11video.c
diffstat 6 files changed, 22 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/win32/SDL_win32modes.c	Fri Dec 04 08:45:08 2009 +0000
+++ b/src/video/win32/SDL_win32modes.c	Fri Dec 04 09:01:48 2009 +0000
@@ -157,7 +157,7 @@
     return SDL_TRUE;
 }
 
-void
+int
 WIN_InitModes(_THIS)
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
@@ -192,6 +192,11 @@
             WIN_AddDisplay(DeviceName);
         }
     }
+    if (_this->num_displays == 0) {
+        SDL_SetError("No displays available");
+        return -1;
+    }
+    return 0;
 }
 
 void
@@ -205,10 +210,11 @@
         if (!WIN_GetDisplayMode(data->DeviceName, i, &mode)) {
             break;
         }
-        if (mode.format != SDL_PIXELFORMAT_UNKNOWN)
+        if (mode.format != SDL_PIXELFORMAT_UNKNOWN) {
             if (!SDL_AddDisplayMode(display, &mode)) {
                 SDL_free(mode.driverdata);
             }
+        }
     }
 }
 
--- a/src/video/win32/SDL_win32modes.h	Fri Dec 04 08:45:08 2009 +0000
+++ b/src/video/win32/SDL_win32modes.h	Fri Dec 04 09:01:48 2009 +0000
@@ -34,7 +34,7 @@
     DEVMODE DeviceMode;
 } SDL_DisplayModeData;
 
-extern void WIN_InitModes(_THIS);
+extern int WIN_InitModes(_THIS);
 extern void WIN_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
 extern int WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
 extern void WIN_QuitModes(_THIS);
--- a/src/video/win32/SDL_win32video.c	Fri Dec 04 08:45:08 2009 +0000
+++ b/src/video/win32/SDL_win32video.c	Fri Dec 04 09:01:48 2009 +0000
@@ -207,7 +207,9 @@
 int
 WIN_VideoInit(_THIS)
 {
-    WIN_InitModes(_this);
+    if (WIN_InitModes(_this) < 0) {
+        return -1;
+    }
 
 #if SDL_VIDEO_RENDER_D3D
     D3D_AddRenderDriver(_this);
--- a/src/video/x11/SDL_x11modes.c	Fri Dec 04 08:45:08 2009 +0000
+++ b/src/video/x11/SDL_x11modes.c	Fri Dec 04 09:01:48 2009 +0000
@@ -118,7 +118,7 @@
     return SDL_PIXELFORMAT_UNKNOWN;
 }
 
-void
+int
 X11_InitModes(_THIS)
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
@@ -168,6 +168,11 @@
         display.driverdata = displaydata;
         SDL_AddVideoDisplay(&display);
     }
+    if (_this->num_displays == 0) {
+        SDL_SetError("No available displays");
+        return -1;
+    }
+    return 0;
 }
 
 /* Global for the error handler */
--- a/src/video/x11/SDL_x11modes.h	Fri Dec 04 08:45:08 2009 +0000
+++ b/src/video/x11/SDL_x11modes.h	Fri Dec 04 09:01:48 2009 +0000
@@ -54,7 +54,7 @@
 
 } SDL_DisplayData;
 
-extern void X11_InitModes(_THIS);
+extern int X11_InitModes(_THIS);
 extern void X11_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
 extern int X11_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
 extern void X11_QuitModes(_THIS);
--- a/src/video/x11/SDL_x11video.c	Fri Dec 04 08:45:08 2009 +0000
+++ b/src/video/x11/SDL_x11video.c	Fri Dec 04 09:01:48 2009 +0000
@@ -255,7 +255,9 @@
     data->WM_DELETE_WINDOW =
         XInternAtom(data->display, "WM_DELETE_WINDOW", False);
 
-    X11_InitModes(_this);
+    if (X11_InitModes(_this) < 0) {
+        return -1;
+    }
 
 #if SDL_VIDEO_RENDER_X11
     X11_AddRenderDriver(_this);