changeset 958:769249e1f3b4

added guards to prevent calling methods on a dead controller (see comment in diff for expl.) + build fix
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 23 Aug 2019 10:16:32 +0200
parents 966c96b694f6
children 13e078adfb94
files Framework/Fonts/GlyphTextureAlphabet.cpp Framework/OpenGL/WebAssemblyOpenGLContext.cpp Framework/Scene2D/RotateSceneTracker.cpp Framework/Scene2D/ZoomSceneTracker.cpp
diffstat 4 files changed, 43 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Fonts/GlyphTextureAlphabet.cpp	Wed Aug 21 16:24:57 2019 +0200
+++ b/Framework/Fonts/GlyphTextureAlphabet.cpp	Fri Aug 23 10:16:32 2019 +0200
@@ -28,9 +28,18 @@
 #include <Core/Images/ImageProcessing.h>
 #include <Core/OrthancException.h>
 
+#ifdef __EMSCRIPTEN__
+/* 
+Avoid this error:
+.../boost/math/special_functions/round.hpp:86:12: warning: implicit conversion from 'std::__2::numeric_limits<int>::type' (aka 'int') to 'float' changes value from 2147483647 to 2147483648 [-Wimplicit-int-float-conversion]
+.../boost/math/special_functions/round.hpp:93:11: note: in instantiation of function template specialization 'boost::math::iround<float, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> >' requested here
+.../orthanc-stone/Framework/Fonts/GlyphTextureAlphabet.cpp:92:28: note: in instantiation of function template specialization 'boost::math::iround<float>' requested here
+*/
+#pragma GCC diagnostic ignored "-Wimplicit-int-float-conversion"
+#endif 
+
 #include <boost/math/special_functions/round.hpp>
 
-
 namespace OrthancStone
 {
   class GlyphTextureAlphabet::GlyphSizeVisitor : public GlyphAlphabet::IGlyphVisitor
--- a/Framework/OpenGL/WebAssemblyOpenGLContext.cpp	Wed Aug 21 16:24:57 2019 +0200
+++ b/Framework/OpenGL/WebAssemblyOpenGLContext.cpp	Fri Aug 23 10:16:32 2019 +0200
@@ -71,7 +71,7 @@
 
       bool IsContextLost()
       {
-        LOG(TRACE) << "IsContextLost() for context " << std::hex() << 
+        LOG(TRACE) << "IsContextLost() for context " << std::hex << context_ << std::dec;
         bool apiFlag = (emscripten_is_webgl_context_lost(context_) != 0);
         isContextLost_ = apiFlag;
         return isContextLost_;
--- a/Framework/Scene2D/RotateSceneTracker.cpp	Wed Aug 21 16:24:57 2019 +0200
+++ b/Framework/Scene2D/RotateSceneTracker.cpp	Fri Aug 23 10:16:32 2019 +0200
@@ -50,18 +50,28 @@
         isFirst_ = false;
       }
 
-      GetController()->SetSceneToCanvasTransform(
-        AffineTransform2D::Combine(
-          AffineTransform2D::CreateRotation(a - referenceAngle_),
-          originalSceneToCanvas_));
-      
-      aligner_.Apply();
+      // The controller is a weak pointer. It could be deleted when the
+      // tracker is still alive (for instance, because of a lost WebGL
+      // context that triggers a recreation of the viewport)
+      if(GetController().get() != NULL)
+      {
+        GetController()->SetSceneToCanvasTransform(
+          AffineTransform2D::Combine(
+            AffineTransform2D::CreateRotation(a - referenceAngle_),
+            originalSceneToCanvas_));
+        
+        aligner_.Apply();
+      }
     }
   }
 
   void RotateSceneTracker::Cancel()
   {
-    GetController()->SetSceneToCanvasTransform(originalSceneToCanvas_);
+      // See remark above
+      if(GetController().get() != NULL)
+      {
+        GetController()->SetSceneToCanvasTransform(originalSceneToCanvas_);
+      }
   }
 
 }
--- a/Framework/Scene2D/ZoomSceneTracker.cpp	Wed Aug 21 16:24:57 2019 +0200
+++ b/Framework/Scene2D/ZoomSceneTracker.cpp	Fri Aug 23 10:16:32 2019 +0200
@@ -76,17 +76,26 @@
 
       double zoom = pow(2.0, z);
 
-      GetController()->SetSceneToCanvasTransform(
-        AffineTransform2D::Combine(
-          AffineTransform2D::CreateScaling(zoom, zoom),
-          originalSceneToCanvas_));
+      // The controller is a weak pointer. It could be deleted when the
+      // tracker is still alive (for instance, because of a lost WebGL
+      // context)
+      if(GetController().get() != NULL)
+      {
+        GetController()->SetSceneToCanvasTransform(
+          AffineTransform2D::Combine(
+            AffineTransform2D::CreateScaling(zoom, zoom),
+            originalSceneToCanvas_));
 
-      aligner_.Apply();
+        aligner_.Apply();
+      }
     }
   }
 
   void ZoomSceneTracker::Cancel()
   {
-    GetController()->SetSceneToCanvasTransform(originalSceneToCanvas_);
+      if(GetController().get() != NULL)
+      {
+        GetController()->SetSceneToCanvasTransform(originalSceneToCanvas_);
+      }
   }
 }