Skip to content

Commit 7b18a5e

Browse files
Synchronize changes from 1.6 master branch [ci skip]
08e1f85 Fix building LOD's crash (#3513)
2 parents a33e960 + 08e1f85 commit 7b18a5e

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

Client/mods/deathmatch/logic/CClientBuilding.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ CClientBuilding::CClientBuilding(class CClientManager* pManager, ElementID ID, u
2424
m_pLowBuilding(nullptr)
2525
{
2626
m_pManager = pManager;
27+
m_pModelInfo = g_pGame->GetModelInfo(usModelId);
2728
SetTypeName("building");
2829
m_pBuildingManager->AddToList(this);
2930
Create();
@@ -99,6 +100,7 @@ void CClientBuilding::SetModel(uint16_t model)
99100
if (CClientBuildingManager::IsValidModel(model))
100101
{
101102
m_usModelId = model;
103+
m_pModelInfo = g_pGame->GetModelInfo(model);
102104
Recreate();
103105
}
104106
}

Client/mods/deathmatch/logic/CClientBuildingManager.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,38 @@ void CClientBuildingManager::DestroyAllForABit()
9898

9999
void CClientBuildingManager::RestoreDestroyed()
100100
{
101-
for (CClientBuilding* building : GetBuildings())
101+
bool hasInvalidLods = true;
102+
while (hasInvalidLods)
102103
{
103-
building->Create();
104+
hasInvalidLods = false;
105+
for (CClientBuilding* building : GetBuildings())
106+
{
107+
const CClientBuilding* highLodBuilding = building->GetHighLodBuilding();
108+
if (highLodBuilding && !highLodBuilding->IsValid())
109+
{
110+
hasInvalidLods = true;
111+
}
112+
else
113+
{
114+
CModelInfo* modelInfo = building->GetModelInfo();
115+
const uint16_t physicalGroup = modelInfo->GetObjectPropertiesGroup();
116+
117+
if (physicalGroup == -1)
118+
{
119+
building->Create();
120+
}
121+
else
122+
{
123+
// GTA creates dynamic models as dummies.
124+
// It's possible that the physical group was changes after
125+
// creating a new building. We can avoid crashes in this case.
126+
modelInfo->SetObjectPropertiesGroup(-1);
127+
building->Create();
128+
modelInfo->SetObjectPropertiesGroup(physicalGroup);
129+
}
130+
131+
}
132+
}
104133
}
105134
}
106135

0 commit comments

Comments
 (0)