Add an "error" label in SDL_CreateRenderer (no op)
authorSylvain Becker <sylvain.becker@gmail.com>
Fri, 28 Jun 2019 16:14:50 +0200
changeset 129098e27bc5f03d8
parent 12908 ec53745bdb23
child 12910 dd9169424181
Add an "error" label in SDL_CreateRenderer (no op)
src/render/SDL_render.c
     1.1 --- a/src/render/SDL_render.c	Fri Jun 28 16:05:20 2019 +0200
     1.2 +++ b/src/render/SDL_render.c	Fri Jun 28 16:14:50 2019 +0200
     1.3 @@ -839,12 +839,12 @@
     1.4  
     1.5      if (!window) {
     1.6          SDL_SetError("Invalid window");
     1.7 -        return NULL;
     1.8 +        goto error;
     1.9      }
    1.10  
    1.11      if (SDL_GetRenderer(window)) {
    1.12          SDL_SetError("Renderer already associated with window");
    1.13 -        return NULL;
    1.14 +        goto error;
    1.15      }
    1.16  
    1.17      if (SDL_GetHint(SDL_HINT_RENDER_VSYNC)) {
    1.18 @@ -888,67 +888,74 @@
    1.19          }
    1.20          if (index == n) {
    1.21              SDL_SetError("Couldn't find matching render driver");
    1.22 -            return NULL;
    1.23 +            goto error;
    1.24          }
    1.25      } else {
    1.26          if (index >= SDL_GetNumRenderDrivers()) {
    1.27              SDL_SetError("index must be -1 or in the range of 0 - %d",
    1.28                           SDL_GetNumRenderDrivers() - 1);
    1.29 -            return NULL;
    1.30 +            goto error;
    1.31          }
    1.32          /* Create a new renderer instance */
    1.33          renderer = render_drivers[index]->CreateRenderer(window, flags);
    1.34          batching = SDL_FALSE;
    1.35      }
    1.36  
    1.37 -    if (renderer) {
    1.38 -        VerifyDrawQueueFunctions(renderer);
    1.39 -
    1.40 -        /* let app/user override batching decisions. */
    1.41 -        if (renderer->always_batch) {
    1.42 -            batching = SDL_TRUE;
    1.43 -        } else if (SDL_GetHint(SDL_HINT_RENDER_BATCHING)) {
    1.44 -            batching = SDL_GetHintBoolean(SDL_HINT_RENDER_BATCHING, SDL_TRUE);
    1.45 +    if (!renderer) {
    1.46 +        goto error;
    1.47 +    }
    1.48 +
    1.49 +    VerifyDrawQueueFunctions(renderer);
    1.50 +
    1.51 +    /* let app/user override batching decisions. */
    1.52 +    if (renderer->always_batch) {
    1.53 +        batching = SDL_TRUE;
    1.54 +    } else if (SDL_GetHint(SDL_HINT_RENDER_BATCHING)) {
    1.55 +        batching = SDL_GetHintBoolean(SDL_HINT_RENDER_BATCHING, SDL_TRUE);
    1.56 +    }
    1.57 +
    1.58 +    renderer->batching = batching;
    1.59 +    renderer->magic = &renderer_magic;
    1.60 +    renderer->window = window;
    1.61 +    renderer->target_mutex = SDL_CreateMutex();
    1.62 +    renderer->scale.x = 1.0f;
    1.63 +    renderer->scale.y = 1.0f;
    1.64 +    renderer->dpi_scale.x = 1.0f;
    1.65 +    renderer->dpi_scale.y = 1.0f;
    1.66 +
    1.67 +    /* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
    1.68 +    renderer->render_command_generation = 1;
    1.69 +
    1.70 +    if (window && renderer->GetOutputSize) {
    1.71 +        int window_w, window_h;
    1.72 +        int output_w, output_h;
    1.73 +        if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
    1.74 +            SDL_GetWindowSize(renderer->window, &window_w, &window_h);
    1.75 +            renderer->dpi_scale.x = (float)window_w / output_w;
    1.76 +            renderer->dpi_scale.y = (float)window_h / output_h;
    1.77          }
    1.78 -
    1.79 -        renderer->batching = batching;
    1.80 -        renderer->magic = &renderer_magic;
    1.81 -        renderer->window = window;
    1.82 -        renderer->target_mutex = SDL_CreateMutex();
    1.83 -        renderer->scale.x = 1.0f;
    1.84 -        renderer->scale.y = 1.0f;
    1.85 -        renderer->dpi_scale.x = 1.0f;
    1.86 -        renderer->dpi_scale.y = 1.0f;
    1.87 -
    1.88 -        /* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
    1.89 -        renderer->render_command_generation = 1;
    1.90 -
    1.91 -        if (window && renderer->GetOutputSize) {
    1.92 -            int window_w, window_h;
    1.93 -            int output_w, output_h;
    1.94 -            if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
    1.95 -                SDL_GetWindowSize(renderer->window, &window_w, &window_h);
    1.96 -                renderer->dpi_scale.x = (float)window_w / output_w;
    1.97 -                renderer->dpi_scale.y = (float)window_h / output_h;
    1.98 -            }
    1.99 -        }
   1.100 -
   1.101 -        if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) {
   1.102 -            renderer->hidden = SDL_TRUE;
   1.103 -        } else {
   1.104 -            renderer->hidden = SDL_FALSE;
   1.105 -        }
   1.106 -
   1.107 -        SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
   1.108 -
   1.109 -        SDL_RenderSetViewport(renderer, NULL);
   1.110 -
   1.111 -        SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
   1.112 -
   1.113 -        SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
   1.114 -                    "Created renderer: %s", renderer->info.name);
   1.115      }
   1.116 +
   1.117 +    if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) {
   1.118 +        renderer->hidden = SDL_TRUE;
   1.119 +    } else {
   1.120 +        renderer->hidden = SDL_FALSE;
   1.121 +    }
   1.122 +
   1.123 +    SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
   1.124 +
   1.125 +    SDL_RenderSetViewport(renderer, NULL);
   1.126 +
   1.127 +    SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
   1.128 +
   1.129 +    SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
   1.130 +                "Created renderer: %s", renderer->info.name);
   1.131 +
   1.132      return renderer;
   1.133 +
   1.134 +error:
   1.135 +    return NULL;
   1.136 +
   1.137  #else
   1.138      SDL_SetError("SDL not built with rendering support");
   1.139      return NULL;