Skip to content

fix(android): drop failed Rive bytes so reattach does not crash - #452

Open
choi138 wants to merge 1 commit into
rive-app:mainfrom
choi138:fix/android-discard-failed-rive-bytes
Open

choi138 wants to merge 1 commit into
rive-app:mainfrom
choi138:fix/android-discard-failed-rive-bytes

Conversation

@choi138

@choi138 choi138 commented Nov 20, 2026

Copy link
Copy Markdown

Problem

When a Rive file fails to load on Android, the error is reported to JS (onError / the red error view), but the app can still crash later with an uncaught MalformedFileException.

  1. RiveAnimationView.setRiveBytes() / setRiveResource() store the source in rendererAttributes.resource before importing it, then call loadFileFromResource.
  2. The import throws a RiveException. RiveReactNativeView catches it and reports it, but rendererAttributes.resource still holds the bad bytes and controller.file stays null.
  3. On the next onAttachedToWindow (Fabric detaches/reattaches views routinely, e.g. on navigation or list recycling), rive-android sees controller.file == null and re-imports rendererAttributes.resource with no try/catch. The same MalformedFileException is now thrown from a framework callback and crashes the app.

A common trigger is a url that returns a non-Rive body with a 200 status (an HTML error page, a CDN placeholder, a truncated download).

Change

  • After catching a RiveException in the resourceName and url load paths, clear rendererAttributes.resource so a later reattach has nothing to re-import.
  • For url sources, check the RIVE magic header before handing the bytes to rive-android. Non-Rive bytes are reported as RNRiveError.MalformedFile (or the error view when the user is not handling errors) with the byte count, and are never stored on the view.

No change to successful loads, event names, or the error types JS already receives.

Testing

  • ./gradlew :rive-react-native:compileDebugKotlin from example/android on this branch: passes.
  • We have shipped the same change as a patch-package patch over 9.6.2 in a production React Native app (Fabric, Reanimated) on Android; the diff here is the same change rebased onto main.
  • Not run on this branch: the example app on a device. Suggested repro: point url at any non-.riv URL that returns 200, then navigate away and back so the view reattaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant