From 3cd8add2fa818e8297c354ac0b9ec195168b8857 Mon Sep 17 00:00:00 2001 From: Michael Behrisch Date: Tue, 16 Jan 2024 10:06:28 +0100 Subject: [PATCH] fixing state cleanup #14198 --- src/microsim/transportables/MSPModel_JuPedSim.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/microsim/transportables/MSPModel_JuPedSim.cpp b/src/microsim/transportables/MSPModel_JuPedSim.cpp index 605ac6fb955f..3c2ef3526701 100644 --- a/src/microsim/transportables/MSPModel_JuPedSim.cpp +++ b/src/microsim/transportables/MSPModel_JuPedSim.cpp @@ -223,7 +223,6 @@ MSPModel_JuPedSim::add(MSTransportable* person, MSStageMoving* stage, SUMOTime n myPedestrianStates.push_back(state); myNumActivePedestrians++; } else { - state->getStage()->setPState(nullptr); // we need to remove the old state reference to avoid double deletion state->reinit(stage, journey, journeyId, startingStage, waypoints); } if (state->isWaitingToEnter()) { @@ -242,7 +241,11 @@ MSPModel_JuPedSim::add(MSTransportable* person, MSStageMoving* stage, SUMOTime n void MSPModel_JuPedSim::remove(MSTransportableStateAdapter* state) { - static_cast(state)->setStage(nullptr); + PState* pstate = static_cast(state); + if (pstate->getStage() != nullptr) { + pstate->getStage()->setPState(nullptr); // we need to remove the old state reference to avoid double deletion + } + pstate->setStage(nullptr); } @@ -822,6 +825,9 @@ MSPModel_JuPedSim::PState::PState(MSPerson* person, MSStageMoving* stage, void MSPModel_JuPedSim::PState::reinit(MSStageMoving* stage, JPS_JourneyDescription journey, JPS_JourneyId journeyId, JPS_StageId stageId, const PositionVector& waypoints) { + if (myStage != nullptr) { + myStage->setPState(nullptr); // we need to remove the old state reference to avoid double deletion + } myStage = stage; myJourney = journey; myJourneyId = journeyId;