Skip to content

Commit bd6233b

Browse files
committed
Fixed crash in automatic TXD resizing #2
1 parent a7e6524 commit bd6233b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

MTA10/core/CGraphics.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,12 @@ bool CGraphics::CopyDataToSurface( IDirect3DSurface9* pSurface, const uchar* pDa
20092009
D3DSURFACE_DESC SurfDesc;
20102010
pSurface->GetDesc( &SurfDesc );
20112011

2012+
uint uiLineWidthBytes = SurfDesc.Width * CRenderItemManager::GetBitsPerPixel( SurfDesc.Format ) / 8;
2013+
2014+
// Check pitch is not too small (i.e from a mipmap level)
2015+
if ( uiDataPitch < uiLineWidthBytes )
2016+
return false;
2017+
20122018
D3DLOCKED_RECT LockedRect;
20132019
if ( FAILED( pSurface->LockRect( &LockedRect, NULL, D3DLOCK_NOSYSLOCK ) ) )
20142020
return false;
@@ -2017,8 +2023,6 @@ bool CGraphics::CopyDataToSurface( IDirect3DSurface9* pSurface, const uchar* pDa
20172023
uint uiSurfPitch = LockedRect.Pitch / CRenderItemManager::GetPitchDivisor( SurfDesc.Format );
20182024
BYTE* pSurfBits = (BYTE*)LockedRect.pBits;
20192025

2020-
uint uiLineWidthBytes = SurfDesc.Width * CRenderItemManager::GetBitsPerPixel( SurfDesc.Format ) / 8;
2021-
20222026
if ( uiLineWidthBytes == uiSurfPitch && uiLineWidthBytes == uiDataPitch )
20232027
{
20242028
// Pitches match byte width

MTA10/game_sa/CRenderWareSA.TxdRightSizing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
119119
int iPitch = pD3DRaster->lockedRect.Pitch;
120120
bool bHasAlpha = pD3DRaster->alpha != 0;
121121
bool bIsCubeTexture = ( pD3DRaster->cubeTextureFlags & 0x01 ) != 0;
122-
bool bHasMipMaps = ( pD3DRaster->textureFlags & 0x01 ) != 0;
122+
bool bHasMipMaps = pRaster->depth != 1;
123123
bool bIsCompressed = ( pD3DRaster->textureFlags & 0x10 ) != 0;
124124

125125
// Check we can do this
@@ -150,7 +150,7 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
150150
header.TextureFormat.vAddressing = ( pTexture->flags & 0xf000 ) >> 12;
151151
memcpy( header.TextureFormat.name, pTexture->name, 32 );
152152
memcpy( header.TextureFormat.maskName, pTexture->mask, 32 );
153-
header.RasterFormat.rasterFormat = pRaster->format << 8; // dxt1 = 0x00000100 or 0x00000200 / dxt3 = 0x00000300
153+
header.RasterFormat.rasterFormat = pRaster->format << 8; // ( dxt1 = 0x00000100 or 0x00000200 / dxt3 = 0x00000300 ) | 0x00008000 mipmaps?
154154
header.RasterFormat.d3dFormat = pD3DRaster->format;
155155
header.RasterFormat.width = uiReqWidth;
156156
header.RasterFormat.height = uiReqHeight;

0 commit comments

Comments
 (0)