# HG changeset patch # User Sam Lantinga # Date 1257653802 0 # Node ID 032e64bbb56c851dad3d75436c2ffc50bc6c56ff # Parent 45ad54b4d9d6a5a7e7f6e68ad77b8bc91bcb4ec8 Skip renderers that fail to initialize diff -r 45ad54b4d9d6 -r 032e64bbb56c src/video/SDL_video.c --- a/src/video/SDL_video.c Mon Nov 02 07:57:51 2009 +0000 +++ b/src/video/SDL_video.c Sun Nov 08 04:16:42 2009 +0000 @@ -1483,19 +1483,35 @@ SDL_SetError("Invalid window ID"); return -1; } + + /* Free any existing renderer */ + SDL_DestroyRenderer(windowID); + if (index < 0) { const char *override = SDL_getenv("SDL_VIDEO_RENDERER"); + if (override) { + int i, n = SDL_GetNumRenderDrivers(); + for (i = 0; i < n; ++i) { + SDL_RenderDriver *driver = + &SDL_CurrentDisplay.render_drivers[i]; + if (SDL_strcasecmp(override, driver->info.name) == 0) { + index = i; + break; + } + } + } + } + if (index < 0) { int n = SDL_GetNumRenderDrivers(); for (index = 0; index < n; ++index) { SDL_RenderDriver *driver = &SDL_CurrentDisplay.render_drivers[index]; - if (override) { - if (SDL_strcasecmp(override, driver->info.name) == 0) { - break; - } - } else { - if ((driver->info.flags & flags) == flags) { + if ((driver->info.flags & flags) == flags) { + /* Create a new renderer instance */ + window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags); + if (window->renderer) { + /* Yay, we got one! */ break; } } @@ -1504,18 +1520,16 @@ SDL_SetError("Couldn't find matching render driver"); return -1; } - } - if (index >= SDL_GetNumRenderDrivers()) { - SDL_SetError("index must be -1 or in the range of 0 - %d", - SDL_GetNumRenderDrivers() - 1); - return -1; + } else { + if (index >= SDL_GetNumRenderDrivers()) { + SDL_SetError("index must be -1 or in the range of 0 - %d", + SDL_GetNumRenderDrivers() - 1); + return -1; + } + + /* Create a new renderer instance */ + window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags); } - /* Free any existing renderer */ - SDL_DestroyRenderer(windowID); - - /* Create a new renderer instance */ - window->renderer = SDL_CurrentDisplay.render_drivers[index] - .CreateRenderer(window, flags); if (window->renderer == NULL) { /* Assuming renderer set its error */