Skip to content

Commit 37d8d4e

Browse files
committed
Fixed memory and thread safety issues in CProxyDirect3D
1 parent 4505174 commit 37d8d4e

File tree

5 files changed

+407
-139
lines changed

5 files changed

+407
-139
lines changed

Client/core/CAdditionalVertexStreamManager.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,14 @@ bool CAdditionalVertexStreamManager::SetAdditionalVertexStream(SCurrentStateInfo
259259
if (FAILED(m_pDevice->GetVertexDeclaration(&pPreviousDecl)))
260260
return false;
261261

262-
if (FAILED(g_pProxyDevice->SetVertexDeclaration(pAdditionalInfo->pVertexDeclaration)))
262+
CScopedActiveProxyDevice proxyDevice;
263+
if (!proxyDevice)
264+
{
265+
SAFE_RELEASE(pPreviousDecl);
266+
return false;
267+
}
268+
269+
if (FAILED(proxyDevice->SetVertexDeclaration(pAdditionalInfo->pVertexDeclaration)))
263270
{
264271
SAFE_RELEASE(pPreviousDecl);
265272
return false;
@@ -268,7 +275,7 @@ bool CAdditionalVertexStreamManager::SetAdditionalVertexStream(SCurrentStateInfo
268275
uint OffsetInBytes = ConvertPTOffset(state.stream1.OffsetInBytes);
269276
if (FAILED(m_pDevice->SetStreamSource(2, pAdditionalInfo->pStreamData, OffsetInBytes, pAdditionalInfo->Stride)))
270277
{
271-
g_pProxyDevice->SetVertexDeclaration(pPreviousDecl);
278+
proxyDevice->SetVertexDeclaration(pPreviousDecl);
272279
SAFE_RELEASE(pPreviousDecl);
273280
return false;
274281
}
@@ -298,7 +305,9 @@ void CAdditionalVertexStreamManager::MaybeUnsetAdditionalVertexStream()
298305
if (bDeviceOperational)
299306
{
300307
// Set prev declaration
301-
g_pProxyDevice->SetVertexDeclaration(m_pOldVertexDeclaration);
308+
CScopedActiveProxyDevice proxyDevice;
309+
if (proxyDevice)
310+
proxyDevice->SetVertexDeclaration(m_pOldVertexDeclaration);
302311

303312
// Unset additional stream
304313
m_pDevice->SetStreamSource(2, nullptr, 0, 0);

Client/core/DXHook/CDirect3DEvents9.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
bool g_bInMTAScene = false;
2626
extern bool g_bInGTAScene;
27+
void ResetGTASceneState();
2728

2829
// Other variables
2930
static uint ms_RequiredAnisotropicLevel = 1;
@@ -177,7 +178,7 @@ void CDirect3DEvents9::OnInvalidate(IDirect3DDevice9* pDevice)
177178
}
178179

179180
g_bInMTAScene = false;
180-
g_bInGTAScene = false;
181+
ResetGTASceneState();
181182

182183
// Invalidate the VMR9 Manager
183184
// CVideoManager::GetSingleton ().OnLostDevice ();
@@ -2098,9 +2099,13 @@ HRESULT CDirect3DEvents9::SetVertexDeclaration(IDirect3DDevice9* pDevice, IDirec
20982099
pDecl = pProxy->GetOriginal();
20992100

21002101
// Update state info
2101-
CProxyDirect3DDevice9::SD3DVertexDeclState* pInfo = MapFind(g_pProxyDevice->m_VertexDeclMap, pProxy);
2102-
if (pInfo)
2103-
g_pDeviceState->VertexDeclState = *pInfo;
2102+
CScopedActiveProxyDevice proxyDevice;
2103+
if (proxyDevice)
2104+
{
2105+
CProxyDirect3DDevice9::SD3DVertexDeclState* pInfo = MapFind(proxyDevice->m_VertexDeclMap, pProxy);
2106+
if (pInfo)
2107+
g_pDeviceState->VertexDeclState = *pInfo;
2108+
}
21042109

21052110
SAFE_RELEASE(pProxy);
21062111
}

0 commit comments

Comments
 (0)