Skip to content

Commit

Permalink
fixing state cleanup #14198
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Jan 16, 2024
1 parent 9e7716f commit 3cd8add
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/microsim/transportables/MSPModel_JuPedSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -242,7 +241,11 @@ MSPModel_JuPedSim::add(MSTransportable* person, MSStageMoving* stage, SUMOTime n

void
MSPModel_JuPedSim::remove(MSTransportableStateAdapter* state) {
static_cast<PState*>(state)->setStage(nullptr);
PState* pstate = static_cast<PState*>(state);
if (pstate->getStage() != nullptr) {
pstate->getStage()->setPState(nullptr); // we need to remove the old state reference to avoid double deletion
}
pstate->setStage(nullptr);
}


Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3cd8add

Please sign in to comment.