comparison OrthancStone/Sources/Scene2DViewport/MeasureTrackers.cpp @ 1685:7896aac14587

Protected against usage of dying viewport
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 25 Nov 2020 12:16:53 +0100
parents 646e581e115b
children 9ac2a65d4172
comparison
equal deleted inserted replaced
1684:fb62c1522193 1685:7896aac14587
58 // to the undo stack 58 // to the undo stack
59 // otherwise, we simply undo it 59 // otherwise, we simply undo it
60 60
61 std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); 61 std::unique_ptr<IViewport::ILock> lock(GetViewportLock());
62 62
63 if (commitResult_) 63 if(lock)
64 lock->GetController().PushCommand(command_); 64 {
65 else 65 if (commitResult_)
66 command_->Undo(); 66 lock->GetController().PushCommand(command_);
67 else
68 command_->Undo();
67 69
68 lock->Invalidate(); 70 lock->Invalidate();
71 }
69 } 72 }
70 73
71 EditMeasureTracker::EditMeasureTracker(boost::weak_ptr<IViewport> viewport, 74 EditMeasureTracker::EditMeasureTracker(boost::weak_ptr<IViewport> viewport,
72 const PointerEvent& e) : 75 const PointerEvent& e) :
73 commitResult_(true), 76 commitResult_(true),
106 // to the undo stack 109 // to the undo stack
107 // otherwise, we simply undo it 110 // otherwise, we simply undo it
108 111
109 std::unique_ptr<IViewport::ILock> lock(GetViewportLock()); 112 std::unique_ptr<IViewport::ILock> lock(GetViewportLock());
110 113
111 if (commitResult_) 114 if(lock)
112 lock->GetController().PushCommand(command_); 115 {
113 else 116 if (commitResult_)
114 command_->Undo(); 117 lock->GetController().PushCommand(command_);
118 else
119 command_->Undo();
115 120
116 lock->Invalidate(); 121 lock->Invalidate();
122 }
117 } 123 }
118 } 124 }
119 125
120 126