From 9d90f1aed5056a3c197225af3dc2cbeadca1bc10 Mon Sep 17 00:00:00 2001 From: Jakob Erdmann Date: Tue, 14 Jun 2016 12:02:41 +0000 Subject: [PATCH] fixing crash when deleting the last lane refs #457 git-svn-id: file:///home/behr_mi/git/sumo_synched/trunk@20962 afbd958f-9f77-42d5-a016-97a22340ccf4 --- sumo/src/netedit/GNEEdge.cpp | 5 ++++- sumo/src/netedit/GNENet.cpp | 37 ++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/sumo/src/netedit/GNEEdge.cpp b/sumo/src/netedit/GNEEdge.cpp index bd4f5680ac0a..2b148e12b3be 100644 --- a/sumo/src/netedit/GNEEdge.cpp +++ b/sumo/src/netedit/GNEEdge.cpp @@ -725,13 +725,16 @@ GNEEdge::addLane(GNELane* lane, const NBEdge::Lane& laneAttrs) { void GNEEdge::removeLane(GNELane* lane) { + if (myLanes.size() == 0) { + throw ProcessError("Should not remove the last lane from an edge\n"); + } if (lane == 0) { lane = myLanes.back(); } myNBEdge.deleteLane(lane->getIndex()); lane->decRef("GNEEdge::removeLane"); myLanes.erase(myLanes.begin() + lane->getIndex()); - if (myLanes.back()->unreferenced()) { + if (lane->unreferenced()) { delete lane; } // udate indices diff --git a/sumo/src/netedit/GNENet.cpp b/sumo/src/netedit/GNENet.cpp index 072d945abddf..90371db1f5f4 100644 --- a/sumo/src/netedit/GNENet.cpp +++ b/sumo/src/netedit/GNENet.cpp @@ -315,24 +315,29 @@ GNENet::deleteEdge(GNEEdge* edge, GNEUndoList* undoList) { void GNENet::deleteLane(GNELane* lane, GNEUndoList* undoList) { - undoList->p_begin("delete lane"); GNEEdge* edge = &lane->getParentEdge(); - const NBEdge::Lane& laneAttrs = edge->getNBEdge()->getLaneStruct(lane->getIndex()); - const bool sidewalk = laneAttrs.permissions == SVC_PEDESTRIAN; - undoList->add(new GNEChange_Lane(edge, lane, laneAttrs, false), true); - if (gSelected.isSelected(GLO_LANE, lane->getGlID())) { - std::set deselected; - deselected.insert(lane->getGlID()); - undoList->add(new GNEChange_Selection(std::set(), deselected, true), true); - } - if (sidewalk) { - edge->getSource()->removeFromCrossings(edge, undoList); - edge->getDest()->removeFromCrossings(edge, undoList); - edge->getSource()->setLogicValid(false, undoList); - edge->getDest()->setLogicValid(false, undoList); + if (edge->getNBEdge()->getNumLanes() == 1) { + // remove the whole edge instead + deleteEdge(edge, undoList); + } else { + undoList->p_begin("delete lane"); + const NBEdge::Lane& laneAttrs = edge->getNBEdge()->getLaneStruct(lane->getIndex()); + const bool sidewalk = laneAttrs.permissions == SVC_PEDESTRIAN; + undoList->add(new GNEChange_Lane(edge, lane, laneAttrs, false), true); + if (gSelected.isSelected(GLO_LANE, lane->getGlID())) { + std::set deselected; + deselected.insert(lane->getGlID()); + undoList->add(new GNEChange_Selection(std::set(), deselected, true), true); + } + if (sidewalk) { + edge->getSource()->removeFromCrossings(edge, undoList); + edge->getDest()->removeFromCrossings(edge, undoList); + edge->getSource()->setLogicValid(false, undoList); + edge->getDest()->setLogicValid(false, undoList); + } + requireRecompute(); + undoList->p_end(); } - requireRecompute(); - undoList->p_end(); }