flutter resource_error ai_generated true

RiveError: Animation cache overflow: too many active animations in the same RiveArtboard

ID: flutter/rive-animation-cache-overflow

Also available as: JSON · Markdown · 中文
76%Fix Rate
81%Confidence
1Evidence
2024-06-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Flutter 3.22 active
Dart 3.4 active
rive_common 0.4.0 active
flare_flutter 3.0.0 active

Root Cause

The Rive animation runtime has a limit on the number of simultaneously playing animations per Artboard (default ~64), which is exceeded when many animations are started without stopping previous ones.

generic

中文

Rive 动画运行时对每个 Artboard 同时播放的动画数量有限制(默认约 64 个),当启动许多动画而未停止之前的动画时,会超过该限制。

Official Documentation

https://pub.dev/packages/rive

Workarounds

  1. 85% success Stop animations before playing new ones: `artboard.animations.forEach((a) => a.stop()); artboard.animationByName('newAnimation')?.play();`
    Stop animations before playing new ones: `artboard.animations.forEach((a) => a.stop()); artboard.animationByName('newAnimation')?.play();`
  2. 80% success Implement a pooling mechanism that reuses animation instances: maintain a list of active animations and remove completed ones using `animation.isActive` check.
    Implement a pooling mechanism that reuses animation instances: maintain a list of active animations and remove completed ones using `animation.isActive` check.
  3. 75% success Use `artboard.animations.clear()` to remove all animation states before loading a new set of animations in a scene transition.
    Use `artboard.animations.clear()` to remove all animation states before loading a new set of animations in a scene transition.

中文步骤

  1. Stop animations before playing new ones: `artboard.animations.forEach((a) => a.stop()); artboard.animationByName('newAnimation')?.play();`
  2. Implement a pooling mechanism that reuses animation instances: maintain a list of active animations and remove completed ones using `animation.isActive` check.
  3. Use `artboard.animations.clear()` to remove all animation states before loading a new set of animations in a scene transition.

Dead Ends

Common approaches that don't work:

  1. 85% fail

    Modifying third-party library source is not maintainable and will be overwritten on package updates; also, increasing cache size may cause memory pressure.

  2. 90% fail

    The runtime does not automatically clean up old animations; each new `play()` call adds to the cache without removing previous instances.

  3. 70% fail

    Rive animations are independent; a single controller cannot manage multiple simultaneous animations with different timelines.