@@ -1515,10 +1515,11 @@ void CGraphics::DrawTexture(CTextureItem* pTexture, float fX, float fY, float fS
15151515 D3DXVECTOR2 scaling (fScaleX * fFileWidth / fCutWidth , fScaleY * fFileHeight / fCutHeight );
15161516 D3DXVECTOR2 rotationCenter (fFileWidth * fScaleX * fCenterX , fFileHeight * fScaleX * fCenterY );
15171517 D3DXVECTOR2 position (fX - fFileWidth * fScaleX * fCenterX , fY - fFileHeight * fScaleY * fCenterY );
1518- D3DXMatrixTransformation2D (&matrix, NULL , NULL , &scaling, &rotationCenter, DegreesToRadians (fRotation ), &position);
1518+ const D3DXVECTOR2* pRotationCenter = fRotation != 0 .0f ? &rotationCenter : NULL ;
1519+ D3DXMatrixTransformation2D (&matrix, NULL , NULL , &scaling, pRotationCenter, DegreesToRadians (fRotation ), &position);
15191520 CheckModes (EDrawMode::DX_SPRITE, m_ActiveBlendMode);
15201521 m_pDXSprite->SetTransform (&matrix);
1521- m_pDXSprite->Draw ((IDirect3DTexture9*)pTexture->m_pD3DTexture , &cutImagePos, NULL , NULL , /* ModifyColorForBlendMode ( */ dwColor /* , blendMode ) */ );
1522+ m_pDXSprite->Draw ((IDirect3DTexture9*)pTexture->m_pD3DTexture , &cutImagePos, NULL , NULL , dwColor);
15221523 EndDrawBatch ();
15231524}
15241525
@@ -1763,7 +1764,7 @@ void CGraphics::DrawQueueItem(const sDrawQueueItem& Item)
17631764 D3DXVECTOR2 scaling (Item.Text .fScaleX , Item.Text .fScaleY );
17641765 D3DXVECTOR2 translation (fPosFracX * Item.Text .fScaleX , fPosFracY * Item.Text .fScaleY ); // Sub-pixel positioning
17651766 D3DXVECTOR2 rotcenter (Item.Text .fRotationCenterX , Item.Text .fRotationCenterY );
1766- D3DXVECTOR2* pRotcenter = Item.Text .fRotation ? &rotcenter : NULL ;
1767+ const D3DXVECTOR2* pRotcenter = Item.Text .fRotation != 0 . 0f ? &rotcenter : NULL ;
17671768 D3DXMatrixTransformation2D (&matrix, NULL , 0 .0f , &scaling, pRotcenter, DegreesToRadians (Item.Text .fRotation ), &translation);
17681769 CheckModes (EDrawMode::DX_SPRITE, Item.blendMode );
17691770 m_pDXSprite->SetTransform (&matrix);
@@ -1789,7 +1790,7 @@ void CGraphics::DrawQueueItem(const sDrawQueueItem& Item)
17891790 const float fCutWidth = cutImagePos.right - cutImagePos.left ;
17901791 const float fCutHeight = cutImagePos.bottom - cutImagePos.top ;
17911792 const D3DXVECTOR2 scaling (Item.Texture .fWidth / fCutWidth , Item.Texture .fHeight / fCutHeight );
1792- const D3DXVECTOR2 rotationCenter (Item. Texture . fWidth * 0 .5f + Item.Texture .fRotCenOffX , Item. Texture . fHeight * 0 .5f + Item.Texture .fRotCenOffY );
1793+ const D3DXVECTOR2 rotationCenter (fFileWidth * 0 .5f + Item.Texture .fRotCenOffX , fFileHeight * 0 .5f + Item.Texture .fRotCenOffY );
17931794 const D3DXVECTOR2 position (Item.Texture .fX , Item.Texture .fY );
17941795 const D3DXVECTOR2* pRotationCenter = Item.Texture .fRotation ? &rotationCenter : NULL ;
17951796 D3DXMATRIX matrix;
@@ -2003,9 +2004,23 @@ void CGraphics::MaybeLeavingMTARenderZone()
20032004// //////////////////////////////////////////////////////////////
20042005void CGraphics::SaveGTARenderStates ()
20052006{
2007+ // Prevent GPU driver hang by checking device state before creating state blocks
2008+ if (m_pDevice->TestCooperativeLevel () != D3D_OK)
2009+ {
2010+ WriteDebugEvent (" CGraphics::SaveGTARenderStates - Device not cooperative, skipping state block creation" );
2011+ return ;
2012+ }
2013+
20062014 SAFE_RELEASE (m_pSavedStateBlock);
2007- // Create a state block.
2008- m_pDevice->CreateStateBlock (D3DSBT_ALL, &m_pSavedStateBlock);
2015+
2016+ // Add error handling for state block creation
2017+ HRESULT hr = m_pDevice->CreateStateBlock (D3DSBT_ALL, &m_pSavedStateBlock);
2018+ if (FAILED (hr))
2019+ {
2020+ WriteDebugEvent (SString (" CGraphics::SaveGTARenderStates - Failed to create state block: %08x" , hr));
2021+ m_pSavedStateBlock = nullptr ;
2022+ return ;
2023+ }
20092024
20102025 // Make sure linear sampling is enabled
20112026 m_pDevice->SetSamplerState (0 , D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
@@ -2025,6 +2040,14 @@ void CGraphics::SaveGTARenderStates()
20252040// //////////////////////////////////////////////////////////////
20262041void CGraphics::RestoreGTARenderStates ()
20272042{
2043+ // Check device state before attempting to restore
2044+ if (m_pDevice->TestCooperativeLevel () != D3D_OK)
2045+ {
2046+ WriteDebugEvent (" CGraphics::RestoreGTARenderStates - Device not cooperative, skipping state restoration" );
2047+ SAFE_RELEASE (m_pSavedStateBlock);
2048+ return ;
2049+ }
2050+
20282051 // Restore these transforms to fix various weird stuff
20292052 m_pDevice->SetTransform (D3DTS_PROJECTION, &g_pDeviceState->TransformState .PROJECTION );
20302053 m_pDevice->SetTransform (D3DTS_WORLD, &g_pDeviceState->TransformState .WORLD );
@@ -2033,7 +2056,12 @@ void CGraphics::RestoreGTARenderStates()
20332056 // Restore the render states
20342057 if (m_pSavedStateBlock)
20352058 {
2036- m_pSavedStateBlock->Apply ();
2059+ // Error handling for state block apply
2060+ HRESULT hr = m_pSavedStateBlock->Apply ();
2061+ if (FAILED (hr))
2062+ {
2063+ WriteDebugEvent (SString (" RestoreGTARenderStates: Failed to apply state block: %08x" , hr));
2064+ }
20372065 SAFE_RELEASE (m_pSavedStateBlock);
20382066 }
20392067}
0 commit comments