From 29c28637505dcdf725085815e91185926a16239b Mon Sep 17 00:00:00 2001 From: pogokeen Date: Thu, 28 Jun 2018 02:00:42 +0000 Subject: [PATCH] sdlayer.cpp: fix software renderer crash affecting Mapster32 due to improper handling of lockcount in videoBeginDrawing()/videoEndDrawing() when using glsurface git-svn-id: https://svn.eduke32.com/eduke32@6933 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/src/sdlayer.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index c327884ae..fd7acc90d 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -1733,10 +1733,15 @@ void videoBeginDrawing(void) modechange = 0; return; } - else if (!nogl) - { - if (offscreenrendering) return; + // lock the frame + if (lockcount++ > 0) + return; + + if (offscreenrendering) return; + + if (!nogl) + { frameplace = (intptr_t)glsurface_getBuffer(); if (modechange) { @@ -1747,12 +1752,6 @@ void videoBeginDrawing(void) return; } - // lock the frame - if (lockcount++ > 0) - return; - - if (offscreenrendering) return; - if (SDL_MUSTLOCK(sdl_buffersurface)) SDL_LockSurface(sdl_buffersurface); frameplace = (intptr_t)sdl_buffersurface->pixels; @@ -1772,7 +1771,7 @@ void videoBeginDrawing(void) // void videoEndDrawing(void) { - if (bpp > 8 || !nogl) + if (bpp > 8) { if (!offscreenrendering) frameplace = 0; return; @@ -1784,7 +1783,7 @@ void videoEndDrawing(void) if (lockcount == 0) return; lockcount = 0; - if (offscreenrendering) return; + if (offscreenrendering || !nogl) return; if (SDL_MUSTLOCK(sdl_buffersurface)) SDL_UnlockSurface(sdl_buffersurface); }