Skip to content

Commit b85414f

Browse files
committed
Fix crash when replace clump with clump or atomic with atomic
1 parent 7ba3275 commit b85414f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Client/game_sa/CRenderWareSA.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ bool CRenderWareSA::ReplaceAllAtomicsInModel(RpClump* pSrc, unsigned short usMod
510510
// Check if new model is clump or atomic
511511
// pSrc->object.type is always RP_TYPE_CLUMP so check number of atomics
512512
// to check if new model is clump or atomic
513-
if (RpClumpGetNumAtomics(pSrc) > 1)
513+
if (RpClumpGetNumAtomics(pSrc) > 1 || (RpClumpGetNumAtomics(pSrc) == 1 && pModelInfo->GetModelType() == eModelInfoType::CLUMP))
514514
{
515515
// Get new interface but with old RwObject
516516
auto* currentNewInterface = static_cast<CClumpModelInfoSAInterface*>(pModelInfo->GetInterface());
@@ -522,7 +522,11 @@ bool CRenderWareSA::ReplaceAllAtomicsInModel(RpClump* pSrc, unsigned short usMod
522522
if (!originalInterface)
523523
return false;
524524

525-
reinterpret_cast<CAtomicModelInfoSAInterface*>(originalInterface)->DeleteRwObject();
525+
if (RpClumpGetNumAtomics(reinterpret_cast<RpClump*>(originalInterface->pRwObject)) == 1)
526+
reinterpret_cast<CAtomicModelInfoSAInterface*>(originalInterface)->DeleteRwObject();
527+
else
528+
currentNewInterface->DeleteRwObject();
529+
526530
currentNewInterface->pRwObject = nullptr;
527531

528532
// Init new RwObject (clump type)
@@ -536,7 +540,7 @@ bool CRenderWareSA::ReplaceAllAtomicsInModel(RpClump* pSrc, unsigned short usMod
536540
// We need to remove the RwObject from the original interface because
537541
// the new interface points to the CAtomicModelInfo vtbl
538542
CBaseModelInfoSAInterface* originalInterface = pModelInfo->GetOriginalInterface();
539-
if (originalInterface)
543+
if (originalInterface && RpClumpGetNumAtomics(reinterpret_cast<RpClump*>(originalInterface->pRwObject)) > 1)
540544
{
541545
reinterpret_cast<CClumpModelInfoSAInterface*>(originalInterface)->DeleteRwObject();
542546
currentInterface->pRwObject = nullptr;

0 commit comments

Comments
 (0)