changeset 1622:0f8d6791b403

fix build by making the destructor of ViewerViewport public
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Nov 2020 07:04:02 +0100
parents 575f512cdf48
children 74be0f498b08
files Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Mon Nov 02 20:45:04 2020 +0100
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Tue Nov 03 07:04:02 2020 +0100
@@ -1738,13 +1738,6 @@
       }*/
   }
 
-  ~ViewerViewport()
-  {
-    emscripten_set_wheel_callback(viewport_->GetCanvasCssSelector().c_str(), this, true, NULL);
-    emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, NULL);
-    emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, NULL);
-  }
-
   static EM_BOOL OnKey(int eventType,
                        const EmscriptenKeyboardEvent *event,
                        void *userData)
@@ -1797,6 +1790,16 @@
   }
 
 public:
+  virtual ~ViewerViewport()
+  {
+    // Unregister the callbacks to avoid any call with a "void*" that
+    // has been destroyed. "WebAssemblyViewport::GetObjectCookie()"
+    // provides a more advanced alternative.
+    emscripten_set_wheel_callback(viewport_->GetCanvasCssSelector().c_str(), this, true, NULL);
+    emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, NULL);
+    emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, false, NULL);
+  }
+
   static boost::shared_ptr<ViewerViewport> Create(OrthancStone::ILoadersContext::ILock& lock,
                                                   const OrthancStone::DicomSource& source,
                                                   const std::string& canvas,