diff OrthancStone/Sources/Scene2D/Internals/FixedPointAligner.cpp @ 1606:874e178f34e9

- ViewportController now has weak ptr to Viewport - Measuring tools + related commands and all trackers now store only a weak_ptr to the Viewport and lock() on demand for usage - LayerHolder and FixedPoint aligner store only a weak_ptr to the Viewport, too - Fixed float/double warning in GrayscaleWindowingSceneTracker
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 28 Oct 2020 20:14:34 +0100
parents 8563ea5d8ae4
children 646e581e115b
line wrap: on
line diff
--- a/OrthancStone/Sources/Scene2D/Internals/FixedPointAligner.cpp	Wed Oct 28 20:06:55 2020 +0100
+++ b/OrthancStone/Sources/Scene2D/Internals/FixedPointAligner.cpp	Wed Oct 28 20:14:34 2020 +0100
@@ -26,19 +26,27 @@
 {
   namespace Internals
   {
-    FixedPointAligner::FixedPointAligner(boost::shared_ptr<IViewport> viewport,
+    FixedPointAligner::FixedPointAligner(boost::weak_ptr<IViewport> viewport,
                                          const ScenePoint2D& p) 
       : viewport_(viewport)
       , canvas_(p)
     {
-      std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
+      std::unique_ptr<IViewport::ILock> lock(GetViewportLock());
       pivot_ = canvas_.Apply(lock->GetController().GetCanvasToSceneTransform());
     }
 
+    IViewport::ILock* FixedPointAligner::GetViewportLock()
+    {
+      boost::shared_ptr<IViewport> viewport = viewport_.lock();
+      if (viewport)
+        return viewport->Lock();
+      else
+        return nullptr;
+    }
     
     void FixedPointAligner::Apply()
     {
-      std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
+      std::unique_ptr<IViewport::ILock> lock(GetViewportLock());
       ScenePoint2D p = canvas_.Apply(
         lock->GetController().GetCanvasToSceneTransform());