From c97afc18a014dccf0c208c21a6dea825f34ceecd Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 1 Aug 2015 00:31:41 -0400 Subject: [PATCH] Fix crashes when changing graphics state --- Sources/Plasma/Apps/plClient/winmain.cpp | 2 ++ .../PubUtilLib/plPipeline/DX/plDXPipeline.cpp | 30 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index c2b7c422..57e9877c 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -1207,6 +1207,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC // Main loop if (gClient && !gClient->GetDone()) { + if (gPendingActivate) + gClient->WindowActivate(gPendingActivateFlag); gClient->SetMessagePumpProc(PumpMessageQueueProc); gClient.Start(); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp index 301ceb4f..779e19b5 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp @@ -2239,25 +2239,23 @@ bool plDXPipeline::IResetDevice() IFindDepthFormat(fSettings.fPresentParams); } HRESULT hr = fD3DDevice->Reset(&fSettings.fPresentParams); - int count = 0; - while( FAILED(hr) ) - { - if(count++ == 25) - { - IPrintDeviceInitError(); - IResetToDefaults(&fSettings.fPresentParams); + // The device is inited the first time on the client loader thread, but this is the main thread + // we expect to get one failure... So let's try recreating the device on the main thread. + if (FAILED(hr)) { + IReleaseDeviceObjects(); + for (int i = 0; true; ++i) { + if (!ICreateDeviceObjects()) + break; + ::Sleep(250); + // Old magic number from reset land + if (i == 25) { + IPrintDeviceInitError(); + IResetToDefaults(&fSettings.fPresentParams); + } } - // Still not ready? This is bad. - // Until we called Reset(), we could make any D3D call we wanted, - // and it would turn into a no-op. But once we call Reset(), until - // the device really is reset, anything but TestCoop/Reset/Release - // has just become illegal. We've already released everything, Reset - // just failed, not much to do but wait and try again. - ::Sleep(250); - hr = fD3DDevice->Reset(&fSettings.fPresentParams); } fSettings.fCurrFVFFormat = 0; - fSettings.fCurrVertexShader = NULL; + fSettings.fCurrVertexShader = nullptr; fManagedAlloced = false; ICreateDynDeviceObjects(); IInitDeviceState();