@@ -261,8 +261,15 @@ function vtkRenderWindowInteractor(publicAPI, model) {
261261 } ;
262262
263263 publicAPI . requestAnimation = ( requestor ) => {
264- model . requestAnimationCount += 1 ;
265- if ( model . requestAnimationCount === 1 ) {
264+ if ( requestor === undefined ) {
265+ vtkErrorMacro ( `undefined requester, can not start animating` ) ;
266+ return ;
267+ }
268+ if ( model . animationRequesters . has ( requestor ) ) {
269+ return ;
270+ }
271+ model . animationRequesters . add ( requestor ) ;
272+ if ( model . animationRequesters . size === 1 ) {
266273 model . lastFrameTime = 0.1 ;
267274 model . lastFrameStart = new Date ( ) . getTime ( ) ;
268275 model . animationRequest = requestAnimationFrame ( publicAPI . handleAnimation ) ;
@@ -274,9 +281,12 @@ function vtkRenderWindowInteractor(publicAPI, model) {
274281 model . vrAnimation || model . animationRequest !== null ;
275282
276283 publicAPI . cancelAnimation = ( requestor ) => {
277- model . requestAnimationCount -= 1 ;
278-
279- if ( model . animationRequest && model . requestAnimationCount === 0 ) {
284+ if ( ! model . animationRequesters . has ( requestor ) ) {
285+ vtkWarningMacro ( `${ requestor } did not request an animation` ) ;
286+ return ;
287+ }
288+ model . animationRequesters . delete ( requestor ) ;
289+ if ( model . animationRequest && model . animationRequesters . size === 0 ) {
280290 cancelAnimationFrame ( model . animationRequest ) ;
281291 model . animationRequest = null ;
282292 publicAPI . endAnimationEvent ( ) ;
@@ -622,7 +632,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
622632 // do not want extra renders as the make the apparent interaction
623633 // rate slower.
624634 publicAPI . render = ( ) => {
625- if ( model . requestAnimationCount === 0 ) {
635+ if ( model . animationRequest === null ) {
626636 publicAPI . forceRender ( ) ;
627637 }
628638 } ;
@@ -858,7 +868,7 @@ const DEFAULT_VALUES = {
858868 recognizeGestures : true ,
859869 currentGesture : 'Start' ,
860870 animationRequest : null ,
861- requestAnimationCount : 0 ,
871+ animationRequesters : new Set ( ) ,
862872 lastFrameTime : 0.1 ,
863873 wheelTimeoutID : 0 ,
864874 moveTimeoutID : 0 ,
0 commit comments