Skip to content

Commit

Permalink
Fixed bug 3169 - GLES2_CreateRenderer does not check SDL_GL_GetAttrib…
Browse files Browse the repository at this point in the history
…ute 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):

BladeGroup/SDL@550389c


I'll be opening a different bug for the underlying issue.
  • Loading branch information
slouken committed Oct 1, 2016
1 parent 67901f5 commit ecea3c4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/render/opengles2/SDL_render_gles2.c
Expand Up @@ -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) ||
Expand Down

0 comments on commit ecea3c4

Please sign in to comment.