BUG SDL2 OpenGL destroying second renderer before using it

Hi, I’ve been playing with sdl, doing multi windowing stuff, and found interesting bug.
If we create two windows with different renderers. and then if we destroy one of that renderers, another one wouldn’t work correctly.
Here’s code to reproduce. Press space, and you’ll see that window1(left window) would go black(but we delete renderer2 from window2)
I’ve tested it on macOS and windows with OpenGL.
This bug affects only OpenGL rendering driver.

Which version of SDL are you using? (Such as “2.0.5”, or other)

I’m using the latest version, 2.0.5

I am unable to reproduce this, using the copy of SDL 2.0.5 for OS X, as provided by LibSDL’s website, at the link, https://www.libsdl.org/release/SDL2-2.0.5.dmg . Further, I was unable to compile your example without some modifications, namely, changing the #include statement.

Where did you get SDL from?

I’ve get sdl from official site, from the official link https://www.libsdl.org/release/SDL2-2.0.5.dmg
include name doesn’t really play a lot here, because that’s just a directory where my sdl installed, it can be different in your case
strange that you can’t reproduce it, because it’s well reproduced for me every time on windows and macOS.
So you mean, that when you launch app, then press space(it destroys renderer2), the left window doesn’t go black?

Ah, ok. I misunderstood the bug. :slight_smile:

Yes, my first window does go black, after pressing space.

And… It shouldn’t be like that, right?

I suspect that this is a bug.

After a bit of digging, I found a few clues, as to the source of the problem:

  1. turning on extra, OpenGL error checking, via the use of


(called just-after SDL_Init), makes the call to SDL_RenderFillRect() fail, with an SDL_GetError() message of:

generic: /Users/davidl/Documents/Code/SDL/SDL/src/render/opengl/SDL_render_gl.c (1266): int GL_RenderFillRects(SDL_Renderer *, const SDL_FRect *, int) GL_INVALID_VALUE (0x0)

  1. After adding in a few, extra, glGetError calls (to SDL itself), it looks like the errors start occurring just-after a call to glUseProgramObjectARB, make from SDL’s GL_SelectShader function, in src/render/opengl/SDL_shaders_gl.c

Additionally to #2: the first error that gets reported after the call to glUseProgramObjectARB, is also GL_INVALID_VALUE. Before that call is made, no error is reported.

This is indeed an SDL bug and I just pushed a fix for it:


1 Like