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;