@@ -54,11 +54,16 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
5454 std::vector < RwTexture* > textureList;
5555 pGame->GetRenderWareSA ()->GetTxdTextures ( textureList, pTxd );
5656
57+ // Double size limit if only one texture in txd
58+ if ( textureList.size () == 1 )
59+ uiSizeLimit *= 2 ;
60+
61+ SString strError;
5762 bool bChanged = false ;
5863 for ( std::vector < RwTexture* > ::iterator iter = textureList.begin () ; iter != textureList.end () ; iter++ )
5964 {
6065 RwTexture* pTexture = *iter;
61- RwTexture* pNewRwTexture = RightSizeTexture ( pTexture, uiSizeLimit );
66+ RwTexture* pNewRwTexture = RightSizeTexture ( pTexture, uiSizeLimit, strError );
6267 if ( pNewRwTexture && pNewRwTexture != pTexture )
6368 {
6469 // Replace texture in txd if changed
@@ -74,6 +79,11 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
7479 }
7580 }
7681
82+ // Log last error
83+ if ( !strError.empty () )
84+ {
85+ AddReportLog ( 8430 , SString ( " RightSizeTxd problem %s with '%s'" , *strError, *strInTxdFilename ), 10 );
86+ }
7787
7888 //
7989 // Save shrunked txd if changed
@@ -103,16 +113,32 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
103113// Returns new texture if did shrink
104114//
105115// ///////////////////////////////////////////////////////////////////////////
106- RwTexture* CRenderWareSA::RightSizeTexture ( RwTexture* pTexture, uint uiSizeLimit )
116+ RwTexture* CRenderWareSA::RightSizeTexture ( RwTexture* pTexture, uint uiSizeLimit, SString& strError )
107117{
108118 // Validate
109119 RwRaster* pRaster = pTexture->raster ;
110120 if ( !pRaster )
121+ {
122+ strError = " pRaster == NULL" ;
111123 return NULL ;
124+ }
112125
113126 RwD3D9Raster* pD3DRaster = (RwD3D9Raster*)( &pRaster->renderResource );
114- if ( !pD3DRaster->texture || !pD3DRaster->lockedSurface || !pD3DRaster->lockedRect .pBits )
127+ if ( !pD3DRaster->texture )
128+ {
129+ strError = " pD3DRaster->texture == NULL" ;
130+ return NULL ;
131+ }
132+ if ( !pD3DRaster->lockedSurface )
133+ {
134+ strError = " pD3DRaster->lockedSurface == NULL" ;
135+ return NULL ;
136+ }
137+ if ( !pD3DRaster->lockedRect .pBits )
138+ {
139+ strError = " pD3DRaster->lockedRect.pBits == NULL" ;
115140 return NULL ;
141+ }
116142
117143 // Get texture info
118144 uint uiWidth = pRaster->width ;
@@ -131,6 +157,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
131157 if ( d3dFormat != D3DFMT_DXT1 && d3dFormat != D3DFMT_DXT3 && d3dFormat != D3DFMT_DXT5 )
132158 return NULL ;
133159
160+ // Double size limit if DXT1
161+ if ( d3dFormat == D3DFMT_DXT1 )
162+ uiSizeLimit *= 2 ;
163+
134164 // Change size
135165 uint uiReqWidth = Min ( uiSizeLimit, uiWidth );
136166 uint uiReqHeight = Min ( uiSizeLimit, uiHeight );
@@ -142,7 +172,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
142172 bool bNeedOwnLock = ( pD3DRaster->lockedLevel != 0 ) || !pD3DRaster->lockedSurface ;
143173 if ( bNeedOwnLock )
144174 if ( FAILED ( pD3DRaster->texture ->LockRect ( 0 , &lockedRect, NULL , D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY ) ) )
175+ {
176+ strError = " pD3DRaster->texture->LockRect failed" ;
145177 return NULL ;
178+ }
146179
147180 // Try resize
148181 CBuffer newPixelBuffer;
@@ -152,7 +185,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
152185 pD3DRaster->texture ->UnlockRect ( 0 );
153186
154187 if ( !bDidResize )
188+ {
189+ strError = " ResizeTextureData failed" ;
155190 return NULL ;
191+ }
156192
157193 // Make new RwTexture from pixels
158194 NativeTexturePC_Header header;
@@ -190,12 +226,21 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
190226 buffer.size = nativeData.GetSize ();
191227 RwStream * rwStream = RwStreamOpen ( STREAM_TYPE_BUFFER, STREAM_MODE_READ, &buffer );
192228 if ( !rwStream )
229+ {
230+ strError = " RwStreamOpen failed" ;
193231 return NULL ;
232+ }
194233
195234 // Read new texture
196235 RwTexture* pNewRwTexture = NULL ;
197236 rwD3D9NativeTextureRead ( rwStream, &pNewRwTexture );
198237 RwStreamClose ( rwStream, NULL );
199238
239+ if ( !pNewRwTexture )
240+ {
241+ strError = " rwD3D9NativeTextureRead failed" ;
242+ return NULL ;
243+ }
244+
200245 return pNewRwTexture;
201246}
0 commit comments