From ab80810bab083b2e1695e66629d97cde0b22b07d Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Mon, 5 Jun 2017 20:57:47 +0100 Subject: [PATCH] Fix crashes when booting non XDK titles --- src/CxbxKrnl/EmuD3D8.cpp | 4 +++- src/CxbxKrnl/HLEIntercept.cpp | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/CxbxKrnl/EmuD3D8.cpp b/src/CxbxKrnl/EmuD3D8.cpp index d74cf80a9..67827d8f3 100644 --- a/src/CxbxKrnl/EmuD3D8.cpp +++ b/src/CxbxKrnl/EmuD3D8.cpp @@ -2161,7 +2161,9 @@ HRESULT WINAPI XTL::EMUPATCH(Direct3D_CreateDevice) Sleep(10); // Set the Xbox g_pD3DDevice pointer to our D3D Device object - *((DWORD*)XRefDataBase[XREF_D3DDEVICE]) = (DWORD)g_XboxD3DDevice; + if (XRefDataBase[XREF_D3DDEVICE] != (xbaddr)nullptr) { + *((DWORD*)XRefDataBase[XREF_D3DDEVICE]) = (DWORD)g_XboxD3DDevice; + } return g_EmuCDPD.hRet; } diff --git a/src/CxbxKrnl/HLEIntercept.cpp b/src/CxbxKrnl/HLEIntercept.cpp index d43fc62af..358d38ea7 100644 --- a/src/CxbxKrnl/HLEIntercept.cpp +++ b/src/CxbxKrnl/HLEIntercept.cpp @@ -199,15 +199,15 @@ void EmuHLEIntercept(Xbe::Header *pXbeHeader) // Fix up Render state and Texture States if (g_SymbolAddresses.find("D3DDeferredRenderState") == g_SymbolAddresses.end()) { - CxbxKrnlCleanup("EmuD3DDeferredRenderState was not found!"); + EmuWarning("EmuD3DDeferredRenderState was not found!"); } if (g_SymbolAddresses.find("D3DDeferredTextureState") == g_SymbolAddresses.end()) { - CxbxKrnlCleanup("EmuD3DDeferredTextureState was not found!"); + EmuWarning("EmuD3DDeferredTextureState was not found!"); } if (g_SymbolAddresses.find("D3DDEVICE") == g_SymbolAddresses.end()) { - CxbxKrnlCleanup("D3DDEVICE was not found!"); + EmuWarning("D3DDEVICE was not found!"); } XTL::EmuD3DDeferredRenderState = (DWORD*)g_SymbolAddresses["D3DDeferredRenderState"]; @@ -215,14 +215,17 @@ void EmuHLEIntercept(Xbe::Header *pXbeHeader) XRefDataBase[XREF_D3DDEVICE] = g_SymbolAddresses["D3DDEVICE"]; // TODO: Move this into a function rather than duplicating from HLE scanning code - for (int v = 0; v<44; v++) { - XTL::EmuD3DDeferredRenderState[v] = XTL::X_D3DRS_UNK; - } + if (XTL::EmuD3DDeferredRenderState != nullptr) { + for (int v = 0; v<44; v++) { + XTL::EmuD3DDeferredRenderState[v] = XTL::X_D3DRS_UNK; + } - for (int s = 0; s<4; s++) { - for (int v = 0; v<32; v++) - XTL::EmuD3DDeferredTextureState[v + s * 32] = X_D3DTSS_UNK; + for (int s = 0; s<4; s++) { + for (int v = 0; v<32; v++) + XTL::EmuD3DDeferredTextureState[v + s * 32] = X_D3DTSS_UNK; + } } + g_HLECacheUsed = true; }