Mercurial > sdl-ios-xcode
diff src/video/SDL_video.c @ 3424:032e64bbb56c
Skip renderers that fail to initialize
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 08 Nov 2009 04:16:42 +0000 |
parents | 64a60c5d502e |
children | 25ccea045c9f |
line wrap: on
line diff
--- 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 */