# HG changeset patch # User Benjamin Golinvaux # Date 1604336058 -3600 # Node ID 9a52bac0c2a7d0a0d39520c71c28967fb8666bbe # Parent 49ba862d3454b99249547088ee9c56a971792757 Added code to clear pending calls to RequestAnimationFrame diff -r 49ba862d3454 -r 9a52bac0c2a7 Applications/Platforms/WebAssembly/WebAssemblyViewport.cpp --- a/Applications/Platforms/WebAssembly/WebAssemblyViewport.cpp Fri Oct 30 17:43:29 2020 +0100 +++ b/Applications/Platforms/WebAssembly/WebAssemblyViewport.cpp Mon Nov 02 17:54:18 2020 +0100 @@ -129,6 +129,7 @@ if (that->compositor_.get() != NULL && that->controller_ /* should always be true */) { + that->animationFrameCallbackIds_.clear(); that->Paint(*that->compositor_, *that->controller_); } @@ -213,7 +214,9 @@ void WebAssemblyViewport::Invalidate() { - emscripten_request_animation_frame(OnRequestAnimationFrame, reinterpret_cast(this)); + long id = emscripten_request_animation_frame(OnRequestAnimationFrame, + reinterpret_cast(this)); + animationFrameCallbackIds_.push_back(id); } void WebAssemblyViewport::FitForPrint() @@ -320,6 +323,13 @@ WebAssemblyViewport::~WebAssemblyViewport() { + // cancel the pending RequestAnimationFrame callbacks + for(size_t i = 0; i < animationFrameCallbackIds_.size(); ++i) + { + long id = animationFrameCallbackIds_[i]; + emscripten_cancel_animation_frame(id); + } + emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, reinterpret_cast(this), false, diff -r 49ba862d3454 -r 9a52bac0c2a7 Applications/Platforms/WebAssembly/WebAssemblyViewport.h --- a/Applications/Platforms/WebAssembly/WebAssemblyViewport.h Fri Oct 30 17:43:29 2020 +0100 +++ b/Applications/Platforms/WebAssembly/WebAssemblyViewport.h Mon Nov 02 17:54:18 2020 +0100 @@ -41,6 +41,7 @@ #include #include +#include #include namespace OrthancStone @@ -60,6 +61,7 @@ bool enableEmscriptenMouseEvents_; unsigned int canvasWidth_; unsigned int canvasHeight_; + std::vector animationFrameCallbackIds_; static EM_BOOL OnRequestAnimationFrame(double time, void *userData);