From ecea3c4a2472070aaa8e1657ba5ea84e7a802e3f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 1 Oct 2016 13:33:32 -0700 Subject: [PATCH] Fixed bug 3169 - GLES2_CreateRenderer does not check SDL_GL_GetAttribute result, causing use of uninitialized data Yann Dirson When attempting to force use of opengles2 renderer with: int wanted_renderer = -1; for (int i = 0; i < numrenderers; i++) { SDL_RendererInfo renderer_info; if (SDL_GetRenderDriverInfo(i, &renderer_info) != 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't get renderer driver info: %s\n", SDL_GetError()); quit(2); } std::cerr << "Renderer " << i << " '" << renderer_info.name << "': flags=0x" << std::hex << renderer_info.flags << std::dec << ", " << renderer_info.num_texture_formats << " texture formats, max=" << renderer_info.max_texture_width << "x" << renderer_info.max_texture_height << "\n"; if (!strcmp(renderer_info.name, "opengles2")) { std::cerr << " selecting!\n"; wanted_renderer = i; } } renderer = SDL_CreateRenderer(window, wanted_renderer, 0); ... on banana pi or raspberry pi I get an error like the following (the actual context profile value varies, being used uninitialized) ERROR: Couldn't create renderer: Unknown OpenGL context profile 900 With this patch I get the following, which should help more pointing to a real problem: ERROR: Couldn't create renderer: Failed getting OpenGL glGetString entry point I pushed a patch (based on master branch of unofficial git mirror): https://github.com/O-Computers/SDL/commit/550389c89f4e73a0a5294f95b9f6e6c18ba48509 I'll be opening a different bug for the underlying issue. --- src/render/opengles2/SDL_render_gles2.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 30d761ad7..c419c0f07 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -1969,9 +1969,15 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags) int profile_mask = 0, major = 0, minor = 0; SDL_bool changed_window = SDL_FALSE; - SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask); - SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major); - SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor); + if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask) < 0) { + goto error; + } + if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major) < 0) { + goto error; + } + if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor) < 0) { + goto error; + } window_flags = SDL_GetWindowFlags(window); if (!(window_flags & SDL_WINDOW_OPENGL) ||