diff Framework/Viewport/WebGLViewportsRegistry.cpp @ 1242:b9b5d4378874 broker

working of WebAssemblyOracle
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 06 Jan 2020 18:08:05 +0100
parents e71ee3e88448
children 0ca50d275b9a
line wrap: on
line diff
--- a/Framework/Viewport/WebGLViewportsRegistry.cpp	Mon Dec 30 10:54:26 2019 +0100
+++ b/Framework/Viewport/WebGLViewportsRegistry.cpp	Mon Jan 06 18:08:05 2020 +0100
@@ -23,6 +23,8 @@
 
 #include <Core/OrthancException.h>
 
+#include <boost/make_shared.hpp>
+
 namespace OrthancStone
 {
   void WebGLViewportsRegistry::LaunchTimer()
@@ -58,16 +60,15 @@
         // At this point, the old canvas is removed from the DOM and
         // replaced by a fresh one with the same ID: Recreate the
         // WebGL context on the new canvas
-        std::auto_ptr<WebGLViewport> viewport;
+        boost::shared_ptr<WebGLViewport> viewport;
           
         {
           std::auto_ptr<IViewport::ILock> lock(it->second->Lock());
-          viewport.reset(new WebGLViewport(it->first, lock->GetController().GetScene()));
+          viewport = boost::make_shared<WebGLViewport>(it->first, lock->GetController().GetScene());
         }
 
         // Replace the old WebGL viewport by the new one
-        delete it->second;
-        it->second = viewport.release();
+        it->second = viewport;
 
         // Tag the fresh canvas as needing a repaint
         {
@@ -100,7 +101,7 @@
   }
 
 
-  void WebGLViewportsRegistry::Add(const std::string& canvasId)
+  boost::shared_ptr<WebGLViewport> WebGLViewportsRegistry::Add(const std::string& canvasId)
   {
     if (viewports_.find(canvasId) != viewports_.end())
     {
@@ -109,7 +110,9 @@
     }
     else
     {
-      viewports_[canvasId] = new WebGLViewport(canvasId);
+      boost::shared_ptr<WebGLViewport> viewport(new WebGLViewport(canvasId));
+      viewports_[canvasId] = viewport;
+      return viewport;
     }
   }
 
@@ -124,11 +127,6 @@
     }
     else
     {
-      if (found->second != NULL)
-      {
-        delete found->second;
-      }
-
       viewports_.erase(found);
     }
   }
@@ -136,14 +134,6 @@
     
   void WebGLViewportsRegistry::Clear()
   {
-    for (Viewports::iterator it = viewports_.begin(); it != viewports_.end(); ++it)
-    {
-      if (it->second != NULL)
-      {
-        delete it->second;
-      }
-    }
-
     viewports_.clear();
   }