Skip to content

Commit 5a62215

Browse files
authored
Improve CProxyDirect3DDevice9::Reset
1 parent f3122d9 commit 5a62215

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

Client/core/DXHook/CProxyDirect3DDevice9.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ HRESULT CProxyDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParamet
289289
{
290290
WriteDebugEvent("CProxyDirect3DDevice9::Reset");
291291

292+
// Validate input parameters
293+
if (!pPresentationParameters)
294+
{
295+
WriteDebugEvent("CProxyDirect3DDevice9::Reset - Invalid presentation parameters");
296+
return D3DERR_INVALIDCALL;
297+
}
298+
292299
// Save presentation parameters
293300
D3DPRESENT_PARAMETERS presentationParametersOrig = *pPresentationParameters;
294301

@@ -302,17 +309,31 @@ HRESULT CProxyDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParamet
302309
// Call the real reset routine.
303310
hResult = DoResetDevice(m_pDevice, pPresentationParameters, presentationParametersOrig);
304311

305-
// Store actual present parameters used
306-
IDirect3DSwapChain9* pSwapChain;
307-
m_pDevice->GetSwapChain(0, &pSwapChain);
308-
pSwapChain->GetPresentParameters(&g_pDeviceState->CreationState.PresentationParameters);
309-
SAFE_RELEASE(pSwapChain);
312+
if (SUCCEEDED(hResult))
313+
{
314+
// Store actual present parameters used
315+
IDirect3DSwapChain9* pSwapChain = nullptr;
316+
HRESULT hrSwapChain = m_pDevice->GetSwapChain(0, &pSwapChain);
317+
if (SUCCEEDED(hrSwapChain) && pSwapChain)
318+
{
319+
pSwapChain->GetPresentParameters(&g_pDeviceState->CreationState.PresentationParameters);
320+
SAFE_RELEASE(pSwapChain);
321+
}
322+
else
323+
{
324+
WriteDebugEvent(SString("Warning: Failed to get swap chain for parameter storage: %08x", hrSwapChain));
325+
}
310326

311-
// Store device creation parameters as well
312-
m_pDevice->GetCreationParameters(&g_pDeviceState->CreationState.CreationParameters);
327+
// Store device creation parameters as well
328+
HRESULT hrCreationParams = m_pDevice->GetCreationParameters(&g_pDeviceState->CreationState.CreationParameters);
329+
if (FAILED(hrCreationParams))
330+
{
331+
WriteDebugEvent(SString("Warning: Failed to get creation parameters: %08x", hrCreationParams));
332+
}
313333

314-
g_pCore->LogEvent(7123, "Direct3D", "Direct3DDevice9::Reset", "Success");
315-
GetVideoModeManager()->PostReset(pPresentationParameters);
334+
// Only perform post-reset operations on successful reset
335+
g_pCore->LogEvent(7123, "Direct3D", "Direct3DDevice9::Reset", "Success");
336+
GetVideoModeManager()->PostReset(pPresentationParameters);
316337

317338
// Update our data.
318339
m_pData->StoreViewport(0, 0, pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);
@@ -335,6 +356,11 @@ HRESULT CProxyDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParamet
335356
const D3DDEVICE_CREATION_PARAMETERS& parameters = g_pDeviceState->CreationState.CreationParameters;
336357

337358
WriteDebugEvent(SString(" Adapter:%d DeviceType:%d BehaviorFlags:0x%x", parameters.AdapterOrdinal, parameters.DeviceType, parameters.BehaviorFlags));
359+
}
360+
else
361+
{
362+
WriteDebugEvent(SString("CProxyDirect3DDevice9::Reset failed with HRESULT: %08x", hResult));
363+
}
338364

339365
return hResult;
340366
}

0 commit comments

Comments
 (0)