local_hero icon indicating copy to clipboard operation
local_hero copied to clipboard

Assertion failed in inn Animation Controller

Open fly-qp opened this issue 3 years ago • 6 comments

The animation works just fine but in the logs it looks very bad. Don't know what to do. Can I leave It like that.

The following assertion was thrown while notifying status listeners for AnimationController:
Assertion failed: file:///Users/apatrck03/Developer/flutter/packages/flutter/lib/src/rendering/object.dart:2221:12
!_debugDisposed
is not true

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3    assertFailed
packages/flutter/src/rendering/object.dart 2221:13                            markNeedsPaint
packages/local_hero/src/rendering/local_hero_layer.dart 34:7                  [_onAnimationStatusChanged]
packages/flutter/src/animation/listener_helpers.dart 233:27                   notifyStatusListeners
packages/flutter/src/animation/animation_controller.dart 814:7                [_checkStatusChanged]
packages/flutter/src/animation/animation_controller.dart 367:5                set value
packages/local_hero/src/rendering/controller.dart 55:19                       [_onAnimationStatusChanged]
packages/flutter/src/animation/listener_helpers.dart 233:27                   notifyStatusListeners
packages/flutter/src/animation/animation_controller.dart 814:7                [_checkStatusChanged]
packages/flutter/src/animation/animation_controller.dart 830:5                [_tick]
packages/flutter/src/scheduler/ticker.dart 238:12                             [_tick]
packages/flutter/src/scheduler/binding.dart 1143:15                           [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1056:106                          <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:13      forEach
packages/flutter/src/scheduler/binding.dart 1054:16                           handleBeginFrame
packages/flutter/src/scheduler/binding.dart 975:5                             [_handleBeginFrame]
lib/_engine/engine/platform_dispatcher.dart 1018:13                           invoke1
lib/_engine/engine/platform_dispatcher.dart 136:5                             invokeOnBeginFrame
lib/_engine/engine.dart 431:45                                                <fn>
The AnimationController notifying status listeners was: AnimationController#2c63e(⏮ 0.000; paused)

fly-qp avatar Oct 06 '21 21:10 fly-qp

Did you find any solution for that?

Urvish24 avatar Oct 19 '21 04:10 Urvish24

Same situation

bambuh avatar Dec 01 '21 15:12 bambuh

Hi.

The solution : add if(!child.debugDisposed) in local_hero_layer.dart before markNeedsPaint();

void _onAnimationStatusChanged(AnimationStatus status) { 
    if (status == AnimationStatus.completed || 
        status == AnimationStatus.dismissed) { 
      if(!child.debugDisposed) markNeedsPaint(); 
    } 
  }

pbouttier avatar Jan 18 '22 14:01 pbouttier

@pbouttier

It getting build fail. can you describe with more information.

Urvish24 avatar Jan 24 '22 07:01 Urvish24

This solution works for me in flutter 2.5.3, with only this fix.

My usage : hero between two listview childrens.

Maybe in other cases, lattest stable this is different.

pbouttier avatar Jan 24 '22 08:01 pbouttier

I am guessing that the animation completed, and the layer was removed. In that case, marking it for paint does not make sense. Haven't tested it (yet), but I think the whole line is redundant.

It seems to be linguistically. If the overlay is removed, when the animation is done, there is nothing to repaint. i've assumed that it is null when it was disposed. Flutter docs say, however, that it is null when assertions are disabled - so to me it seems not the best way to check for it, anyway.

Also, for null-safety the line is a little different

void _onAnimationStatusChanged(AnimationStatus status) { if (status == AnimationStatus.completed || status == AnimationStatus.dismissed) { if(!child.debugDisposed ?? true) markNeedsPaint(); } }

FrankDomburg avatar Mar 23 '22 13:03 FrankDomburg

Hi.

The solution : add if(!child.debugDisposed) in local_hero_layer.dart before markNeedsPaint();

void _onAnimationStatusChanged(AnimationStatus status) { 
    if (status == AnimationStatus.completed || 
        status == AnimationStatus.dismissed) { 
      if(!child.debugDisposed) markNeedsPaint(); 
    } 
  }

Be careful, this might break the animation in release mode (debug mode works fine though)

singularity-s0 avatar Feb 10 '23 16:02 singularity-s0

It's work, thanks

juarezfranco avatar Mar 26 '23 16:03 juarezfranco

Hi, I ran into the same issue. The solution with the debugDisposed check will not work in a release build because debug variables should not be used outside of assert statements.

Instead, a check for the attached property should solve the issue:

// in 'lib/src/rendering/local_hero_layer.dart'
void _onAnimationStatusChanged(AnimationStatus status) {
  if (!attached) {
    return;
  }
  if (status == AnimationStatus.completed ||
      status == AnimationStatus.dismissed) {
    markNeedsPaint();
  }
}

Snonky avatar Sep 26 '23 12:09 Snonky