Skip to content

Commit b1d19c2

Browse files
committed
Fix white textures on vanilla models sharing a TXD slot
1 parent 91b6bee commit b1d19c2

1 file changed

Lines changed: 34 additions & 8 deletions

File tree

Client/game_sa/CRenderWareSA.TextureReplacing.cpp

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5468,13 +5468,38 @@ bool CRenderWareSA::ModelInfoTXDAddTextures(SReplacementTextures* pReplacementTe
54685468
}
54695469
else if (itPrevIsolated == g_IsolatedTxdByModel.end())
54705470
{
5471-
// Keep vanilla replacements on a private TXD so later model
5472-
// loads and child TXDs dont pick them up from the shared slot.
5473-
if (!AllocateIsolatedTxdForVanillaModel(usModelId, usCurrentTxdId))
5471+
// Only isolate when the shared TXD already has replacement
5472+
// textures for a different model - multiple CClientTXDs
5473+
// imported to different models on the same slot would corrupt
5474+
// each other. Without a conflict, let textures go into the
5475+
// shared TXD so other models on the same slot can still find
5476+
// them through SA's texture walk.
5477+
bool bHasConflict = false;
5478+
auto itExisting = ms_ModelTexturesInfoMap.find(usCurrentTxdId);
5479+
if (itExisting != ms_ModelTexturesInfoMap.end())
5480+
{
5481+
for (const SReplacementTextures* pExisting : itExisting->second.usedByReplacements)
5482+
{
5483+
if (!pExisting || pExisting == pReplacementTextures)
5484+
continue;
5485+
5486+
if (pExisting->usedInTxdIds.count(usCurrentTxdId) > 0 &&
5487+
pExisting->usedInModelIds.count(usModelId) == 0)
5488+
{
5489+
bHasConflict = true;
5490+
break;
5491+
}
5492+
}
5493+
}
5494+
5495+
if (bHasConflict)
54745496
{
5475-
AddReportLog(9401, SString("AllocateIsolatedTxdForVanillaModel failed for model %u, deferring", usModelId));
5476-
QueuePendingReplacement(usModelId, pReplacementTextures, 0, 0);
5477-
return false;
5497+
if (!AllocateIsolatedTxdForVanillaModel(usModelId, usCurrentTxdId))
5498+
{
5499+
AddReportLog(9401, SString("AllocateIsolatedTxdForVanillaModel failed for model %u (conflict), deferring", usModelId));
5500+
QueuePendingReplacement(usModelId, pReplacementTextures, 0, 0);
5501+
return false;
5502+
}
54785503
}
54795504
}
54805505
else
@@ -5603,8 +5628,9 @@ bool CRenderWareSA::ModelInfoTXDAddTextures(SReplacementTextures* pReplacementTe
56035628
}
56045629
else
56055630
{
5606-
QueuePendingReplacement(usModelId, pReplacementTextures, 0, 0);
5607-
return false;
5631+
// Non-isolated vanilla model during reapply: fall through to
5632+
// the shared TXD injection below so textures get re-added
5633+
// after a streaming reload.
56085634
}
56095635
}
56105636
}

0 commit comments

Comments
 (0)