From 9ab84c503dbeb5db3b2c4f1ecd8d27f2e4500d84 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Tue, 25 Feb 2020 20:53:02 +0000 Subject: [PATCH] refine 4315 a bit. At least on windows, an overlay needs to be locked before the real pitch data is returned instead of a wild pointer Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4334 --- src/gui/sdlmain.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 84cee0f3..291387c9 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -900,13 +900,18 @@ dosurface: if (!(flags & GFX_CAN_32) || (flags & GFX_RGBONLY)) goto dosurface; if (!GFX_SetupSurfaceScaled(0,0)) goto dosurface; sdl.overlay = SDL_CreateYUVOverlay(width * 2, height, SDL_UYVY_OVERLAY, sdl.surface); - - if (sdl.overlay && sdl.overlay->pitches[0] < 4 * width) { - // We get a distorted image in this case. Cleanup and go to surface. - LOG_MSG("SDL: overlay pitch is too small. (%u < %" sBitfs(u) ")", sdl.overlay->pitches[0], width * 4); - SDL_FreeYUVOverlay(sdl.overlay); - sdl.overlay = 0; + + if (sdl.overlay && SDL_LockYUVOverlay(sdl.overlay) == 0) { + //Need to lock in order to get real pitchdata (at least on windows with dx backend) + if (sdl.overlay->pitches[0] < 4 * width) { + // We get a distorted image in this case. Cleanup and go to surface. + LOG_MSG("SDL: overlay pitch is too small. (%u < %" sBitfs(u) ")", sdl.overlay->pitches[0], width * 4); + SDL_UnlockYUVOverlay(sdl.overlay); + SDL_FreeYUVOverlay(sdl.overlay); + sdl.overlay = 0; + } else SDL_UnlockYUVOverlay(sdl.overlay); } + if (!sdl.overlay) { LOG_MSG("SDL: Failed to create overlay, switching back to surface."); goto dosurface;