Viewer + specific GLTF + play-once : Maximum call stack size exceeded

Hi!

I have a bug reduced to a specific use case :

  • Using babylon viewer 5.7.0
  • Using the option play-once
  • Using a big (but not huge) gltf that loads fine if play-once is not activated

The result is :

index.ts:4 Uncaught RangeError: Maximum call stack size exceeded
    at Observer.callback (src/index.ts:4:23)
    at Observable.notifyObservers (dev/core/src/Misc/observable.ts:364:49)
    at Animatable.animatable.onAnimationEnd (dev/core/src/Animations/animationGroup.ts:366:47)
    at Animatable._raiseOnAnimationEnd (dev/core/src/Animations/animatable.ts:305:18)
    at Animatable.stop (dev/core/src/Animations/animatable.ts:352:22)
    at AnimationGroup.stop (dev/core/src/Animations/animationGroup.ts:478:25)
    at GroupModelAnimation.stop (src/index.ts:4:23)
    at Observer.callback (src/index.ts:4:23)
    at Observable.notifyObservers (dev/core/src/Misc/observable.ts:364:49)
    at Animatable.animatable.onAnimationEnd (dev/core/src/Animations/animationGroup.ts:366:47)

I’ve looked at the code, I have made a hackish attempt at a fix which work, in the code of GroupModelAnimation:

@@ -275228,7 +275228,7 @@ class GroupModelAnimation {
         this._state = AnimationState.INIT;
         this._playMode = AnimationPlayMode.LOOP;
         this._animationGroup.onAnimationEndObservable.add(() => {
-            this.stop();
+            this.stop(true);
             this._state = AnimationState.ENDED;
         });
     }
@@ -275365,8 +275365,10 @@ class GroupModelAnimation {
      * Stop the animation.
      * This will fail silently if the animation group is already stopped.
      */
-    stop() {
-        this._animationGroup.stop();
+    stop(doNotPropagate) {
+        if(doNotPropagate === undefined || doNotPropagate == false) {
+               this._animationGroup.stop();
+        }

This fixes the problem (the idea is : if I get the signal from _animationGroup than animation is ended, then do not ask _animationGroup to stop), but I am not sure this is conceptually correct.

Is there something am I missing? Is this correction in the good direction? Thank you all!

Good catch!

I believe there is a different solution:

@@ -275228,7 +275228,7 @@ class GroupModelAnimation {
         this._state = AnimationState.INIT;
         this._playMode = AnimationPlayMode.LOOP;
         this._animationGroup.onAnimationEndObservable.add(() => {
-            this.stop();
             this._state = AnimationState.ENDED;
+            this.stop();
         });
     }
@@ -275365,8 +275365,10 @@ class GroupModelAnimation {
      * Stop the animation.
      * This will fail silently if the animation group is already stopped.
      */
-    stop() {
-        this._animationGroup.stop();
+    stop(doNotPropagate) {
+        if(this._state !== AnimationState.ENDED) {
+               this._animationGroup.stop();
+        }

will that work?

I will be very happy to submit the fix :slight_smile:

Thank you!

Yes I confirm this also fix the bug, and looks more like the right one :slight_smile:
Things in my big GLTFs seems to load a bit faster, but it may be just what I want to see!
And yes I’d be happy if you submit the fix, thank you!

1 Like

i’ll do it later today :slight_smile:

Thanks!!

:raised_hands: thanks!