Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GL_CreateRenderer() crashes when using opengl32.dll #3047

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

GL_CreateRenderer() crashes when using opengl32.dll #3047

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.9
Reported for operating system, platform: Windows 10, All

Comments on the original bug report:

On 2018-11-01 03:24:58 +0000, Cameron Gutman wrote:

Created attachment 3432
Fix SDL_CreateRenderer() crash

I received a bug report that a user was seeing my app crashing randomly. We narrowed it down to likely being a display driver crash (but the app crash was not expected). When this happens, the D3D device loss triggers us to try to create a new renderer. This ends up hitting GL_CreateRenderer() after D3D9 renderer creation fails, where it tries to look up OpenGL functions with GL_LoadFunctions().

Since the display driver is recovering, we don't have a working third party OGL implementation. The stock opengl32.dll lacks some of the functions that SDL looks for in GL_LoadFunctions(). The first one that's missing is glBlendEquation() which was introduced in OGL 1.2. When we hit this one, GL_LoadFunctions() fails, causing GL_DestroyRenderer() to be called. This eventually ends up calling a null pointer when SDL tries to invoke data->glViewport() inside GL_UpdateViewport().

The attached patch avoids caling GL_DestroyRenderer() until GL_LoadFunctions() has succeeded. I've also updated the GLES2 code which also had the same bug.

0:000> .excr
rax=0000000000000438 rbx=000002cae06b16b0 rcx=0000000000000000
rdx=0000000000000438 rsi=000002cae06b16b0 rdi=000002cae06b14c0
rip=0000000000000000 rsp=000000dc2ab06598 rbp=000002cae06b14c0
r8=0000000000000000 r9=0000000000000000 r10=000002cae06a9ea8
r11=000000dc2ab06590 r12=0000000000000000 r13=00000000000002d0
r14=000002cae06b16b0 r15=0000000000000001
iopl=0 nv up ei pl nz na pe nc
cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010202
00000000`00000000 ?? ???
0:000> k
*** Stack trace for last set context - .thread/.cxr resets it

Child-SP RetAddr Call Site

00 000000dc2ab06598 00007ffa26d586d4 0x0
01 000000dc2ab065a0 00007ffa26d54019 SDL2!GL_UpdateViewport+0xa4 [c:\users\aicom\sdl\src\render\opengl\sdl_render_gl.c @ 1081]
02 000000dc2ab06620 00007ffa26d55053 SDL2!GL_ActivateRenderer+0x69 [c:\users\aicom\sdl\src\render\opengl\sdl_render_gl.c @ 304]
03 000000dc2ab06650 00007ffa26d53f52 SDL2!GL_DestroyRenderer+0x33 [c:\users\aicom\sdl\src\render\opengl\sdl_render_gl.c @ 1599]
04 000000dc2ab066c0 00007ffa26d5ef68 SDL2!GL_CreateRenderer+0x572 [c:\users\aicom\sdl\src\render\opengl\sdl_render_gl.c @ 570]
05 000000dc2ab06720 00007ff71f086e51 SDL2!SDL_CreateRenderer_REAL+0x138 [c:\users\aicom\sdl\src\render\sdl_render.c @ 349]
06 000000dc2ab06790 0000000000000000 Moonlight!SdlRenderer::initialize+0x51 [c:\moonlight-qt\app\streaming\video\ffmpeg-renderers\sdlvid.cpp @ 69]

0:000> ?? data
struct GL_RenderData * 0x000002cae06b16b0 +0x000 context : 0x0000000000040000 Void
+0x008 debug_enabled : 0 ( SDL_FALSE )
+0x00c GL_ARB_debug_output_supported : 0 ( SDL_FALSE )
+0x010 errors : 0n0
+0x018 error_messages : (null)
+0x020 next_error_callback : (null)
+0x028 next_error_userparam : (null)
+0x030 GL_ARB_texture_non_power_of_two_supported : 0 ( SDL_FALSE )
+0x034 GL_ARB_texture_rectangle_supported : 0 ( SDL_FALSE )
+0x038 current :
+0x044 GL_EXT_framebuffer_object_supported : 0 ( SDL_FALSE )
+0x048 framebuffers : (null)
+0x050 glBegin : 0x00007ffa37ef6470 void opengl32!glBegin+0 +0x058 glBindTexture : 0x00007ffa37ef6d60 void opengl32!glBindTexture+0
+0x060 glBlendEquation : (null)
+0x068 glBlendFuncSeparate : (null)
+0x070 glClear : (null)
+0x078 glClearColor : (null)
+0x080 glColor3fv : (null)
+0x088 glColor4f : (null)
+0x090 glDeleteTextures : (null)
+0x098 glDepthFunc : (null)
+0x0a0 glDisable : (null)
+0x0a8 glDrawPixels : (null)
+0x0b0 glEnable : (null)
+0x0b8 glEnd : (null)
+0x0c0 glGenTextures : (null)
+0x0c8 glGetError : (null)
+0x0d0 glGetIntegerv : (null)
+0x0d8 glGetPointerv : (null)
+0x0e0 glGetString : (null)
+0x0e8 glLineWidth : (null)
+0x0f0 glLoadIdentity : (null)
+0x0f8 glMatrixMode : (null)
+0x100 glOrtho : (null)
+0x108 glPixelStorei : (null)
+0x110 glPointSize : (null)
+0x118 glPopMatrix : (null)
+0x120 glPushMatrix : (null)
+0x128 glRasterPos2i : (null)
+0x130 glReadBuffer : (null)
+0x138 glReadPixels : (null)
+0x140 glRectf : (null)
+0x148 glRotated : (null)
+0x150 glRotatef : (null)
+0x158 glScissor : (null)
+0x160 glShadeModel : (null)
+0x168 glTexCoord2f : (null)
+0x170 glTexEnvf : (null)
+0x178 glTexImage2D : (null)
+0x180 glTexParameteri : (null)
+0x188 glTexSubImage2D : (null)
+0x190 glTranslatef : (null)
+0x198 glVertex2f : (null)
+0x1a0 glVertex3fv : (null)
+0x1a8 glViewport : (null)
+0x1b0 GL_ARB_multitexture_supported : 0 ( SDL_FALSE )
+0x1b8 glActiveTextureARB : (null)
+0x1c0 num_texture_units : 0n0
+0x1c8 glGenFramebuffersEXT : (null)
+0x1d0 glDeleteFramebuffersEXT : (null)
+0x1d8 glFramebufferTexture2DEXT : (null)
+0x1e0 glBindFramebufferEXT : (null)
+0x1e8 glCheckFramebufferStatusEXT : (null)
+0x1f0 shaders : (null)

On 2018-11-01 09:27:06 +0000, Ozkan Sezer wrote:

Sam: This lookes correct to me and applied it:
http://hg.libsdl.org/SDL/rev/84618d571795

If you agree, then please close this.

On 2018-11-01 10:03:29 +0000, Sam Lantinga wrote:

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant