Skip to content

Commit c6ffee0

Browse files
committed
Addendum to 290e554
1 parent 9b74e06 commit c6ffee0

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

Client/game_sa/CRenderWareSA.TextureReplacing.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4759,7 +4759,7 @@ void CRenderWareSA::ModelInfoTXDRemoveTextures(SReplacementTextures* pReplacemen
47594759
std::vector<RwTexture*> currentTextures;
47604760
GetTxdTextures(currentTextures, pInfo->pTxd);
47614761

4762-
if (!pInfo->originalTextures.empty() && currentTextures.empty())
4762+
if (currentTextures.empty())
47634763
return false;
47644764

47654765
if (currentTextures.size() != pInfo->originalTextures.size())
@@ -4770,6 +4770,33 @@ void CRenderWareSA::ModelInfoTXDRemoveTextures(SReplacementTextures* pReplacemen
47704770
if (pInfo->originalTextures.find(pTex) == pInfo->originalTextures.end())
47714771
return false;
47724772
}
4773+
4774+
// Prevent PopulateOriginalTextures contamination:
4775+
// If originalTextures was snapshotted while MTA textures were still linked in the
4776+
// TXD, the pointer comparison above gives a false positive. Cross-check against
4777+
// g_LeakedMasterTextures to detect masters or copies (via shared raster) that
4778+
// should not be in a clean TXD.
4779+
if (!g_LeakedMasterTextures.empty())
4780+
{
4781+
for (RwTexture* pTex : currentTextures)
4782+
{
4783+
if (!pTex)
4784+
continue;
4785+
4786+
if (g_LeakedMasterTextures.count(pTex) != 0)
4787+
return false;
4788+
4789+
if (pTex->raster)
4790+
{
4791+
for (RwTexture* pMaster : g_LeakedMasterTextures)
4792+
{
4793+
if (pMaster && pMaster->raster == pTex->raster)
4794+
return false;
4795+
}
4796+
}
4797+
}
4798+
}
4799+
47734800
return true;
47744801
};
47754802

0 commit comments

Comments
 (0)