From 533e245ea343f1b35ac70631a71988b031284f61 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] 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 | 22 +++++++++++++++------- src/utils/modelinfomgr.cpp | 6 ------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/features/sirens.cpp b/src/features/sirens.cpp index 0fcfe46..032f7c7 100755 --- a/src/features/sirens.cpp +++ b/src/features/sirens.cpp @@ -557,7 +557,9 @@ void Sirens::EventCtor(CVehicle *pVeh) { if (Sirens::modelData.contains(pVeh->m_nModelIndex)) { - vehicleData[pVeh] = new VehicleSiren(pVeh); + if (!vehicleData.contains(pVeh)) { + vehicleData[pVeh] = new VehicleSiren(pVeh); + } } } @@ -611,13 +613,19 @@ 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)) { - 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}; + } } } } diff --git a/src/utils/modelinfomgr.cpp b/src/utils/modelinfomgr.cpp index 2565a01..b3b04b0 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;