Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Don't add any renderers if you can't add any displays
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 4, 2009
1 parent f540152 commit 4a3f57f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/video/win32/SDL_win32modes.c
Expand Up @@ -157,7 +157,7 @@ WIN_AddDisplay(LPTSTR DeviceName)
return SDL_TRUE;
}

void
int
WIN_InitModes(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
Expand Down Expand Up @@ -192,6 +192,11 @@ WIN_InitModes(_THIS)
WIN_AddDisplay(DeviceName);
}
}
if (_this->num_displays == 0) {
SDL_SetError("No displays available");
return -1;
}
return 0;
}

void
Expand All @@ -205,10 +210,11 @@ WIN_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
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);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/video/win32/SDL_win32modes.h
Expand Up @@ -34,7 +34,7 @@ typedef struct
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);
Expand Down
4 changes: 3 additions & 1 deletion src/video/win32/SDL_win32video.c
Expand Up @@ -207,7 +207,9 @@ VideoBootStrap WIN32_bootstrap = {
int
WIN_VideoInit(_THIS)
{
WIN_InitModes(_this);
if (WIN_InitModes(_this) < 0) {
return -1;
}

#if SDL_VIDEO_RENDER_D3D
D3D_AddRenderDriver(_this);
Expand Down
7 changes: 6 additions & 1 deletion src/video/x11/SDL_x11modes.c
Expand Up @@ -118,7 +118,7 @@ X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
return SDL_PIXELFORMAT_UNKNOWN;
}

void
int
X11_InitModes(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
Expand Down Expand Up @@ -168,6 +168,11 @@ X11_InitModes(_THIS)
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 */
Expand Down
2 changes: 1 addition & 1 deletion src/video/x11/SDL_x11modes.h
Expand Up @@ -54,7 +54,7 @@ typedef struct

} 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);
Expand Down
4 changes: 3 additions & 1 deletion src/video/x11/SDL_x11video.c
Expand Up @@ -255,7 +255,9 @@ X11_VideoInit(_THIS)
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);
Expand Down

0 comments on commit 4a3f57f

Please sign in to comment.