From 2ebeff4691e30027dbf5201ab72df7cf20527fb2 Mon Sep 17 00:00:00 2001 From: CanerKaraca23 <37447503+CanerKaraca23@users.noreply.github.com> Date: Sat, 4 Apr 2026 11:11:30 +0000 Subject: [PATCH 1/2] Fix sirens crash by initializing vehicleData instead of skipping frames * Remove temporary frame-count workaround in `ModelInfoMgr::SetEditableMaterialsCB`. * Initialize `vehicleData` entry lazily in `Sirens` `RegisterMaterialColProvider` lambda, preventing null pointer dereferencing when calling `vehicleData[pVeh]->GetCurrentState()`. --- src/features/sirens.cpp | 3 +++ src/utils/modelinfomgr.cpp | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/features/sirens.cpp b/src/features/sirens.cpp index 0fcfe462..fb6b9be2 100755 --- a/src/features/sirens.cpp +++ b/src/features/sirens.cpp @@ -611,6 +611,9 @@ void Sirens::Init() int matIdx = GetSirenIndex(pVeh, pMat); if (matIdx != - 1) { + if (!vehicleData.contains(pVeh)) { + vehicleData[pVeh] = new VehicleSiren(pVeh); + } int curState = vehicleData[pVeh]->GetCurrentState(); auto& state = modelData[pVeh->m_nModelIndex]->States[curState]; if (state->Materials.contains(matIdx)) { diff --git a/src/utils/modelinfomgr.cpp b/src/utils/modelinfomgr.cpp index af43e7f9..aa692231 100755 --- a/src/utils/modelinfomgr.cpp +++ b/src/utils/modelinfomgr.cpp @@ -240,12 +240,6 @@ RpMaterial *ModelInfoMgr::SetEditableMaterialsCB(RpMaterial *material, void *dat { auto &data = m_VehData.Get(pCurVeh); - // Sirens crash fix TODO: remove this and fix it - if (iLightIndex == eMaterialType::SirenLight && data.nFrameCount <= 10) - { - return material; - } - bool lightOn = false; data.m_MatAvail[iLightIndex] = true; From 1275df6b9526d0d2cf652b3f9459d7a2dcfc25d1 Mon Sep 17 00:00:00 2001 From: CanerKaraca23 <37447503+CanerKaraca23@users.noreply.github.com> Date: Sat, 4 Apr 2026 11:30:13 +0000 Subject: [PATCH 2/2] Fix sirens crash by initializing vehicleData instead of skipping frames * Remove temporary frame-count workaround in `ModelInfoMgr::SetEditableMaterialsCB`. * Initialize `vehicleData` entry lazily in `Sirens` `RegisterMaterialColProvider` lambda, preventing null pointer dereferencing when calling `vehicleData[pVeh]->GetCurrentState()`. * Add bounds checking for `curState` against `modelData[pVeh->m_nModelIndex]->States.size()`. --- src/features/sirens.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/features/sirens.cpp b/src/features/sirens.cpp index fb6b9be2..4e28a982 100755 --- a/src/features/sirens.cpp +++ b/src/features/sirens.cpp @@ -615,12 +615,15 @@ void Sirens::Init() vehicleData[pVeh] = new VehicleSiren(pVeh); } int curState = vehicleData[pVeh]->GetCurrentState(); - auto& state = modelData[pVeh->m_nModelIndex]->States[curState]; - if (state->Materials.contains(matIdx)) { - if (modelData[pVeh->m_nModelIndex]->isImVehFtSiren) { - return MatStateColor{state->Materials[matIdx]->Color, state->Materials[matIdx]->Color}; - } else { - return MatStateColor{state->Materials[matIdx]->Color, DEFAULT_MAT_COL}; + + if (curState >= 0 && curState < modelData[pVeh->m_nModelIndex]->States.size()) { + auto& state = modelData[pVeh->m_nModelIndex]->States[curState]; + if (state->Materials.contains(matIdx)) { + if (modelData[pVeh->m_nModelIndex]->isImVehFtSiren) { + return MatStateColor{state->Materials[matIdx]->Color, state->Materials[matIdx]->Color}; + } else { + return MatStateColor{state->Materials[matIdx]->Color, DEFAULT_MAT_COL}; + } } } }