Browse Source

Fix crashes when changing graphics state

Adam Johnson 10 years ago
parent
commit
c97afc18a0
  1. 2
      Sources/Plasma/Apps/plClient/winmain.cpp
  2. 30
      Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp

2
Sources/Plasma/Apps/plClient/winmain.cpp

@ -1207,6 +1207,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC
// Main loop // Main loop
if (gClient && !gClient->GetDone()) { if (gClient && !gClient->GetDone()) {
if (gPendingActivate)
gClient->WindowActivate(gPendingActivateFlag);
gClient->SetMessagePumpProc(PumpMessageQueueProc); gClient->SetMessagePumpProc(PumpMessageQueueProc);
gClient.Start(); gClient.Start();

30
Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp

@ -2239,25 +2239,23 @@ bool plDXPipeline::IResetDevice()
IFindDepthFormat(fSettings.fPresentParams); IFindDepthFormat(fSettings.fPresentParams);
} }
HRESULT hr = fD3DDevice->Reset(&fSettings.fPresentParams); HRESULT hr = fD3DDevice->Reset(&fSettings.fPresentParams);
int count = 0; // The device is inited the first time on the client loader thread, but this is the main thread
while( FAILED(hr) ) // we expect to get one failure... So let's try recreating the device on the main thread.
{ if (FAILED(hr)) {
if(count++ == 25) IReleaseDeviceObjects();
{ for (int i = 0; true; ++i) {
IPrintDeviceInitError(); if (!ICreateDeviceObjects())
IResetToDefaults(&fSettings.fPresentParams); 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.fCurrFVFFormat = 0;
fSettings.fCurrVertexShader = NULL; fSettings.fCurrVertexShader = nullptr;
fManagedAlloced = false; fManagedAlloced = false;
ICreateDynDeviceObjects(); ICreateDynDeviceObjects();
IInitDeviceState(); IInitDeviceState();

Loading…
Cancel
Save