diff OrthancStone/Sources/Scene2DViewport/LayerHolder.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
line wrap: on
line diff
--- a/OrthancStone/Sources/Scene2DViewport/LayerHolder.cpp	Wed Nov 25 12:16:33 2020 +0100
+++ b/OrthancStone/Sources/Scene2DViewport/LayerHolder.cpp	Wed Nov 25 12:16:53 2020 +0100
@@ -96,15 +96,18 @@
   void LayerHolder::DeleteLayers()
   {
     std::unique_ptr<IViewport::ILock> lock(GetViewportLock());
-    Scene2D& scene = lock->GetController().GetScene();
-
-    for (int i = 0; i < textLayerCount_ + polylineLayerCount_; ++i)
+    if (lock)
     {
-      ORTHANC_ASSERT(scene.HasLayer(baseLayerIndex_ + i), "No layer");
-      scene.DeleteLayer(baseLayerIndex_ + i);
+      Scene2D& scene = lock->GetController().GetScene();
+
+      for (int i = 0; i < textLayerCount_ + polylineLayerCount_; ++i)
+      {
+        ORTHANC_ASSERT(scene.HasLayer(baseLayerIndex_ + i), "No layer");
+        scene.DeleteLayer(baseLayerIndex_ + i);
+      }
+      baseLayerIndex_ = -1;
+      lock->Invalidate();
     }
-    baseLayerIndex_ = -1;
-    lock->Invalidate();
   }
   
   PolylineSceneLayer* LayerHolder::GetPolylineLayer(int index /*= 0*/)