Skip to content

Commit 0dfe140

Browse files
committed
Replace unsafe Matrix4/D3DMATRIX casts in TerrainTex for Generals
1 parent bdd37cc commit 0dfe140

File tree

1 file changed

+11
-5
lines changed
  • Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient

1 file changed

+11
-5
lines changed

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,14 +788,20 @@ void LightMapTerrainTextureClass::Apply(unsigned int stage)
788788

789789
D3DXMATRIX inv;
790790
float det;
791-
D3DXMatrixInverse(&inv, &det, (D3DXMATRIX*)&curView);
791+
D3DXMATRIX d3dCurView(
792+
curView[0][0], curView[0][1], curView[0][2], curView[0][3],
793+
curView[1][0], curView[1][1], curView[1][2], curView[1][3],
794+
curView[2][0], curView[2][1], curView[2][2], curView[2][3],
795+
curView[3][0], curView[3][1], curView[3][2], curView[3][3]
796+
);
797+
D3DXMatrixInverse(&inv, &det, &d3dCurView);
792798
D3DXMATRIX scale;
793799
D3DXMatrixScaling(&scale, STRETCH_FACTOR, STRETCH_FACTOR,1);
794800
inv *=scale;
795801
if (stage==0) {
796-
DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE0, *((Matrix4x4*)&inv));
802+
DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE0, inv);
797803
} if (stage==1) {
798-
DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE1, *((Matrix4x4*)&inv));
804+
DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE1, inv);
799805
}
800806

801807

@@ -1066,7 +1072,7 @@ void CloudMapTerrainTextureClass::Apply(unsigned int stage)
10661072
DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
10671073
DX8Wrapper::Set_DX8_Texture_Stage_State( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
10681074

1069-
DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE0, *((Matrix4x4*)&inv));
1075+
DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE0, inv);
10701076

10711077
// Disable 3rd stage just in case.
10721078
DX8Wrapper::Set_DX8_Texture_Stage_State( 2, D3DTSS_COLOROP, D3DTOP_DISABLE );
@@ -1085,7 +1091,7 @@ void CloudMapTerrainTextureClass::Apply(unsigned int stage)
10851091
DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ALPHAARG1, D3DTA_CURRENT );
10861092
DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
10871093

1088-
DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE1, *((Matrix4x4*)&inv));
1094+
DX8Wrapper::_Set_DX8_Transform(D3DTS_TEXTURE1, inv);
10891095
}
10901096
}
10911097

0 commit comments

Comments
 (0)