From 9aa22534aba8bf414ddd650cbcfdb9a26f5d5ede Mon Sep 17 00:00:00 2001 From: narzoul Date: Sun, 3 Apr 2016 11:15:21 +0200 Subject: [PATCH] Fixed crash due to setting clipper on uninitialized palette converter --- DDrawCompat/CompatGdi.cpp | 2 ++ DDrawCompat/CompatPaletteConverter.cpp | 16 +++++++--------- DDrawCompat/CompatPaletteConverter.h | 3 ++- DDrawCompat/RealPrimarySurface.cpp | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/DDrawCompat/CompatGdi.cpp b/DDrawCompat/CompatGdi.cpp index 733f8ef..1eddfd4 100644 --- a/DDrawCompat/CompatGdi.cpp +++ b/DDrawCompat/CompatGdi.cpp @@ -9,6 +9,7 @@ #include "CompatGdiPaintHandlers.h" #include "CompatGdiScrollFunctions.h" #include "CompatGdiWinProc.h" +#include "CompatPaletteConverter.h" #include "CompatPrimarySurface.h" #include "DDrawProcs.h" #include "RealPrimarySurface.h" @@ -231,6 +232,7 @@ namespace CompatGdi void installHooks() { InitializeCriticalSection(&g_gdiCriticalSection); + CompatPaletteConverter::init(); if (CompatGdiDcCache::init()) { g_ddUnlockBeginEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); diff --git a/DDrawCompat/CompatPaletteConverter.cpp b/DDrawCompat/CompatPaletteConverter.cpp index e30cd8e..a2d1150 100644 --- a/DDrawCompat/CompatPaletteConverter.cpp +++ b/DDrawCompat/CompatPaletteConverter.cpp @@ -87,7 +87,7 @@ namespace namespace CompatPaletteConverter { - bool init() + bool create() { if (CompatPrimarySurface::displayMode.pixelFormat.dwRGBBitCount > 8 && RealPrimarySurface::s_surfaceDesc.ddpfPixelFormat.dwRGBBitCount > 8) @@ -95,14 +95,6 @@ namespace CompatPaletteConverter return true; } - static bool isFirstInit = true; - if (isFirstInit) - { - InitializeCriticalSection(&g_criticalSection); - initHalftonePalette(); - isFirstInit = false; - } - void* bits = nullptr; HBITMAP dib = createDibSection(bits); if (!dib) @@ -136,6 +128,12 @@ namespace CompatPaletteConverter return true; } + void init() + { + InitializeCriticalSection(&g_criticalSection); + initHalftonePalette(); + } + HDC lockDc() { EnterCriticalSection(&g_criticalSection); diff --git a/DDrawCompat/CompatPaletteConverter.h b/DDrawCompat/CompatPaletteConverter.h index b58ea0d..859502d 100644 --- a/DDrawCompat/CompatPaletteConverter.h +++ b/DDrawCompat/CompatPaletteConverter.h @@ -6,7 +6,8 @@ namespace CompatPaletteConverter { - bool init(); + bool create(); + void init(); HDC lockDc(); IDirectDrawSurface7* lockSurface(); void release(); diff --git a/DDrawCompat/RealPrimarySurface.cpp b/DDrawCompat/RealPrimarySurface.cpp index 2ea60fd..313e661 100644 --- a/DDrawCompat/RealPrimarySurface.cpp +++ b/DDrawCompat/RealPrimarySurface.cpp @@ -187,7 +187,7 @@ HRESULT RealPrimarySurface::create(DirectDraw& dd) s_surfaceDesc.dwSize = sizeof(s_surfaceDesc); g_frontBuffer->lpVtbl->GetSurfaceDesc(g_frontBuffer, &s_surfaceDesc); - if (!CompatPaletteConverter::init()) + if (!CompatPaletteConverter::create()) { g_frontBuffer->lpVtbl->Release(g_frontBuffer); g_frontBuffer = nullptr;