Skip to content

Commit 7ad38bb

Browse files
committed
Fix SA crash @ 0x003F3825
1 parent 1909eaa commit 7ad38bb

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Client/game_sa/CRenderWareSA.TextureReplacing.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,9 @@ void CRenderWareSA::ModelInfoTXDRemoveTextures(SReplacementTextures* pReplacemen
316316

317317
swapMap[pOldTexture] = pOriginalTexture;
318318

319-
// Only restore original textures early if this is the last replacement set for this TXD
320-
// Otherwise, other replacement sets might still be using the TXD
321-
bool isLastReplacement = (pInfo->usedByReplacements.size() == 1);
322-
if (pOriginalTexture && isLastReplacement && !RwTexDictionaryContainsTexture(pInfo->pTxd, pOriginalTexture))
319+
// Always restore original textures to prevent them from becoming orphaned and GC'd
320+
// This is crucial for proper cleanup even when multiple replacement sets use the same TXD
321+
if (pOriginalTexture && !RwTexDictionaryContainsTexture(pInfo->pTxd, pOriginalTexture))
323322
RwTexDictionaryAddTexture(pInfo->pTxd, pOriginalTexture);
324323
}
325324

@@ -373,7 +372,7 @@ void CRenderWareSA::ModelInfoTXDRemoveTextures(SReplacementTextures* pReplacemen
373372
// Free replaced textures that aren't in originalTextures (prevents leak)
374373
for (RwTexture* pReplacedTexture : perTxdInfo.replacedOriginals)
375374
{
376-
if (pReplacedTexture && !ListContains(pInfo->originalTextures, pReplacedTexture))
375+
if (pReplacedTexture && SharedUtil::IsReadablePointer(pReplacedTexture, sizeof(RwTexture)) && !ListContains(pInfo->originalTextures, pReplacedTexture))
377376
RwTextureDestroy(pReplacedTexture);
378377
}
379378

0 commit comments

Comments
 (0)