# HG changeset patch # User Benjamin Golinvaux # Date 1604336135 -3600 # Node ID 4c9e68291467a93a0e85872845df071cd8d3088a # Parent 9a52bac0c2a7d0a0d39520c71c28967fb8666bbe Added code to remove the wheel callback in dtor, to prevent access to dead object diff -r 9a52bac0c2a7 -r 4c9e68291467 Applications/Samples/Common/RtViewerView.h --- a/Applications/Samples/Common/RtViewerView.h Mon Nov 02 17:54:18 2020 +0100 +++ b/Applications/Samples/Common/RtViewerView.h Mon Nov 02 17:55:35 2020 +0100 @@ -52,12 +52,18 @@ , currentPlane_(0) , projection_(projection) , ctLayer_(0) + , canvasId_(canvasId) { viewport_ = CreateViewport(canvasId); FLOATING_INFOTEXT_LAYER_ZINDEX = 6; FIXED_INFOTEXT_LAYER_ZINDEX = 7; } + ~RtViewerView() + { + CleanupViewportEvents(); + } + /** This method is called when the scene transform changes. It allows to recompute the visual elements whose content depend upon the scene transform @@ -112,6 +118,7 @@ const std::string& value); boost::shared_ptr GetApp(); boost::shared_ptr CreateViewport(const std::string& canvasId); + void CleanupViewportEvents(); void DisplayInfoText(); void HideInfoText(); void DisplayFloatingCtrlInfoText(const PointerEvent& e); @@ -141,5 +148,6 @@ boost::shared_ptr viewport_; int ctLayer_; + std::string canvasId_; }; } diff -r 9a52bac0c2a7 -r 4c9e68291467 Applications/Samples/Sdl/RtViewer/RtViewerSdl.cpp --- a/Applications/Samples/Sdl/RtViewer/RtViewerSdl.cpp Mon Nov 02 17:54:18 2020 +0100 +++ b/Applications/Samples/Sdl/RtViewer/RtViewerSdl.cpp Mon Nov 02 17:55:35 2020 +0100 @@ -88,6 +88,11 @@ return SdlOpenGLViewport::Create(canvasId, 1024, 1024, false); } + void RtViewerView::CleanupViewportEvents() + { + // only used in WASM at the moment + } + void RtViewerApp::ProcessOptions(int argc, char* argv[]) { namespace po = boost::program_options; diff -r 9a52bac0c2a7 -r 4c9e68291467 Applications/Samples/WebAssembly/RtViewer/RtViewerWasm.cpp --- a/Applications/Samples/WebAssembly/RtViewer/RtViewerWasm.cpp Mon Nov 02 17:54:18 2020 +0100 +++ b/Applications/Samples/WebAssembly/RtViewer/RtViewerWasm.cpp Mon Nov 02 17:55:35 2020 +0100 @@ -109,6 +109,18 @@ return viewport; } + void RtViewerView::CleanupViewportEvents() + { + void* userData = reinterpret_cast(this); + std::string selector = "#" + canvasId_; + emscripten_set_wheel_callback_on_thread( + selector.c_str(), + userData, + false, + NULL, + EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD); + } + void RtViewerView::TakeScreenshot(const std::string& target, unsigned int canvasWidth, unsigned int canvasHeight)