Mercurial > hg > orthanc-stone
changeset 1619:4c9e68291467
Added code to remove the wheel callback in dtor, to prevent access to dead object
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 02 Nov 2020 17:55:35 +0100 |
parents | 9a52bac0c2a7 |
children | 1151e25d7311 |
files | Applications/Samples/Common/RtViewerView.h Applications/Samples/Sdl/RtViewer/RtViewerSdl.cpp Applications/Samples/WebAssembly/RtViewer/RtViewerWasm.cpp |
diffstat | 3 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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<RtViewerApp> GetApp(); boost::shared_ptr<IViewport> CreateViewport(const std::string& canvasId); + void CleanupViewportEvents(); void DisplayInfoText(); void HideInfoText(); void DisplayFloatingCtrlInfoText(const PointerEvent& e); @@ -141,5 +148,6 @@ boost::shared_ptr<IViewport> viewport_; int ctLayer_; + std::string canvasId_; }; }
--- 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;
--- 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<void*>(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)