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):

550389c89f


I'll be opening a different bug for the underlying issue.
This commit is contained in:
Sam Lantinga 2016-10-01 13:33:32 -07:00
parent 67901f537c
commit ecea3c4a24
1 changed files with 9 additions and 3 deletions

View File

@ -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) ||