comparison 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
comparison
equal deleted inserted replaced
3423:45ad54b4d9d6 3424:032e64bbb56c
1481 1481
1482 if (!window) { 1482 if (!window) {
1483 SDL_SetError("Invalid window ID"); 1483 SDL_SetError("Invalid window ID");
1484 return -1; 1484 return -1;
1485 } 1485 }
1486
1487 /* Free any existing renderer */
1488 SDL_DestroyRenderer(windowID);
1489
1486 if (index < 0) { 1490 if (index < 0) {
1487 const char *override = SDL_getenv("SDL_VIDEO_RENDERER"); 1491 const char *override = SDL_getenv("SDL_VIDEO_RENDERER");
1492 if (override) {
1493 int i, n = SDL_GetNumRenderDrivers();
1494 for (i = 0; i < n; ++i) {
1495 SDL_RenderDriver *driver =
1496 &SDL_CurrentDisplay.render_drivers[i];
1497 if (SDL_strcasecmp(override, driver->info.name) == 0) {
1498 index = i;
1499 break;
1500 }
1501 }
1502 }
1503 }
1504 if (index < 0) {
1488 int n = SDL_GetNumRenderDrivers(); 1505 int n = SDL_GetNumRenderDrivers();
1489 for (index = 0; index < n; ++index) { 1506 for (index = 0; index < n; ++index) {
1490 SDL_RenderDriver *driver = 1507 SDL_RenderDriver *driver =
1491 &SDL_CurrentDisplay.render_drivers[index]; 1508 &SDL_CurrentDisplay.render_drivers[index];
1492 1509
1493 if (override) { 1510 if ((driver->info.flags & flags) == flags) {
1494 if (SDL_strcasecmp(override, driver->info.name) == 0) { 1511 /* Create a new renderer instance */
1495 break; 1512 window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags);
1496 } 1513 if (window->renderer) {
1497 } else { 1514 /* Yay, we got one! */
1498 if ((driver->info.flags & flags) == flags) {
1499 break; 1515 break;
1500 } 1516 }
1501 } 1517 }
1502 } 1518 }
1503 if (index == n) { 1519 if (index == n) {
1504 SDL_SetError("Couldn't find matching render driver"); 1520 SDL_SetError("Couldn't find matching render driver");
1505 return -1; 1521 return -1;
1506 } 1522 }
1507 } 1523 } else {
1508 if (index >= SDL_GetNumRenderDrivers()) { 1524 if (index >= SDL_GetNumRenderDrivers()) {
1509 SDL_SetError("index must be -1 or in the range of 0 - %d", 1525 SDL_SetError("index must be -1 or in the range of 0 - %d",
1510 SDL_GetNumRenderDrivers() - 1); 1526 SDL_GetNumRenderDrivers() - 1);
1511 return -1; 1527 return -1;
1512 } 1528 }
1513 /* Free any existing renderer */ 1529
1514 SDL_DestroyRenderer(windowID); 1530 /* Create a new renderer instance */
1515 1531 window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags);
1516 /* Create a new renderer instance */ 1532 }
1517 window->renderer = SDL_CurrentDisplay.render_drivers[index]
1518 .CreateRenderer(window, flags);
1519 1533
1520 if (window->renderer == NULL) { 1534 if (window->renderer == NULL) {
1521 /* Assuming renderer set its error */ 1535 /* Assuming renderer set its error */
1522 return -1; 1536 return -1;
1523 } 1537 }