Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,16 +801,28 @@ void CModelInfoSA::SetTextureDictionaryID(unsigned short usID)
if (!m_pInterface)
return;

// Remove ref from the old TXD
CTxdStore_RemoveRef(m_pInterface->usTextureDictionary);
// CBaseModelInfo::AddRef adds references to model and TXD
// We need transfer added references from old TXD to new TXD
size_t referencesCount = m_pInterface->usNumberOfRefs;

// +1 reference for active rwObject
// The current textures will be removed in RpAtomicDestroy
// RenderWare uses an additional reference counter per texture
if (m_pInterface->pRwObject)
referencesCount++;

for (size_t i = 0; i < referencesCount; i++)
CTxdStore_RemoveRef(m_pInterface->usTextureDictionary);

// Store vanilla TXD ID
if (!MapContains(ms_DefaultTxdIDMap, m_dwModelID))
ms_DefaultTxdIDMap[m_dwModelID] = m_pInterface->usTextureDictionary;

// Set new TXD and increase ref of it
m_pInterface->usTextureDictionary = usID;
CTxdStore_AddRef(usID);

for (size_t i = 0; i < referencesCount; i++)
CTxdStore_AddRef(usID);
}

void CModelInfoSA::ResetTextureDictionaryID()
Expand Down
4 changes: 3 additions & 1 deletion Client/game_sa/CRenderWareSA.TextureReplacing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,10 @@ void CRenderWareSA::ModelInfoTXDRemoveTextures(SReplacementTextures* pReplacemen
ListRemove(currentTextures, pOriginalTexture);
}
assert(currentTextures.empty());
#endif

int32_t refsCount = CTxdStore_GetNumRefs(pInfo->usTxdId);
assert(refsCount > 0, "Should have at least one TXD reference here");
#endif
// Remove info
CTxdStore_RemoveRef(pInfo->usTxdId);
MapRemove(ms_ModelTexturesInfoMap, usTxdId);
Expand Down
Loading