1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Fixed issues with releasing the real primary surface

The palette converter surface was being released even when it was null,
leading to potential problems with releasing the primary surface.

The update thread is also no longer terminated on each release.
Termination may have been necessary more often than expected because
the thread may be waiting on the DirectDraw critical section on release.
There doesn't seem to be any issues with letting the OS clean up
the running thread on exit instead.
This commit is contained in:
narzoul 2015-12-28 13:54:11 +01:00
parent 3610edb117
commit 61efdcb438

View File

@ -108,15 +108,11 @@ namespace
{
g_frontBuffer = nullptr;
g_backBuffer = nullptr;
g_paletteConverterSurface->lpVtbl->Release(g_paletteConverterSurface);
g_paletteConverterSurface = nullptr;
SetEvent(g_updateEvent);
if (WAIT_TIMEOUT == WaitForSingleObject(g_updateThread, 500))
if (g_paletteConverterSurface)
{
TerminateThread(g_updateThread, 0);
g_paletteConverterSurface->lpVtbl->Release(g_paletteConverterSurface);
g_paletteConverterSurface = nullptr;
}
g_updateThread = nullptr;
CloseHandle(g_updateEvent);
g_updateEvent = nullptr;
@ -153,6 +149,11 @@ namespace
Compat::origProcs.AcquireDDThreadLock();
ResetEvent(g_updateEvent);
if (!g_frontBuffer)
{
Compat::origProcs.ReleaseDDThreadLock();
continue;
}
if (!g_isFlipEvent)
{
@ -233,9 +234,16 @@ HRESULT RealPrimarySurface::create(DirectDraw& dd)
QueryPerformanceFrequency(&g_qpcFrequency);
g_updateEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
g_updateThread = CreateThread(nullptr, 0, &updateThreadProc, nullptr, 0, nullptr);
SetThreadPriority(g_updateThread, THREAD_PRIORITY_ABOVE_NORMAL);
if (!g_updateEvent)
{
g_updateEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
}
if (!g_updateThread)
{
g_updateThread = CreateThread(nullptr, 0, &updateThreadProc, nullptr, 0, nullptr);
SetThreadPriority(g_updateThread, THREAD_PRIORITY_ABOVE_NORMAL);
}
g_frontBuffer->lpVtbl->SetPrivateData(g_frontBuffer,
IID_IReleaseNotifier, &g_releaseNotifier, sizeof(&g_releaseNotifier), DDSPD_IUNKNOWNPOINTER);