Skip to content

fix(android): prevent IllegalStateException in cleanup on destroyed p…#23

Merged
theashraf merged 1 commit intoLottieFiles:mainfrom
YOOGOMJA:fix/android-cleanup-destroyed-player-crash
Oct 21, 2025
Merged

fix(android): prevent IllegalStateException in cleanup on destroyed p…#23
theashraf merged 1 commit intoLottieFiles:mainfrom
YOOGOMJA:fix/android-cleanup-destroyed-player-crash

Conversation

@YOOGOMJA
Copy link
Contributor

🐛 Problem

The app crashes with IllegalStateException: DotLottiePlayer object has already been destroyed when a component containing DotLottie is unmounted quickly (e.g., closing a BottomSheet or navigating away).

Stacktrace

java.lang.IllegalStateException: DotLottiePlayer object has already been destroyed
at com.dotlottie.dlplayer.DotLottiePlayer.stop(dotlottie_player.kt:7281)
at com.lottiefiles.dotlottie.core.compose.runtime.DotLottieController.stop(DotLottieController.kt:139)
at com.dotlottiereactnative.DotlottieReactNativeView.cleanup(DotlottieReactNativeView.kt:299)
at com.dotlottiereactnative.DotlottieReactNativeView.onDetachedFromWindow(DotlottieReactNativeView.kt:295)

Root Cause

Race condition in the cleanup lifecycle:

  1. DotLottiePlayer object gets destroyed
  2. onDetachedFromWindow() triggers cleanup()
  3. cleanup() attempts to call stop() on the already destroyed player
  4. App crashes with IllegalStateException

✅ Solution

Added try-catch block in the cleanup() method to gracefully handle cases where the player is already destroyed. This prevents the crash while still allowing proper cleanup of resources that are still available.

🧪 Testing

  • Tested with BottomSheet that frequently mounts/unmounts DotLottie component
  • Tested rapid navigation between screens with DotLottie animations
  • No crashes observed after the fix
  • Proper cleanup still occurs when player is not destroyed

…layer

Add try-catch block to handle IllegalStateException that occurs when
DotLottiePlayer object is already destroyed during cleanup in onDetachedFromWindow.

This fixes a race condition where the player gets destroyed before cleanup
can call stop(), causing app crashes when components unmount quickly
(e.g., in BottomSheet scenarios).
@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2025

⚠️ No Changeset found

Latest commit: b76763d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@theashraf
Copy link
Member

Thanks @YOOGOMJA! Merging this fix.

Follow-up needed: Implement Dispose pattern to prevent double-cleanup. Current try-catch addresses the symptom but doesn't prevent onDetachedFromWindow() being called multiple times (can happen with Fabric). Will create issue to track.

@theashraf theashraf merged commit 3648963 into LottieFiles:main Oct 21, 2025
6 checks passed
@YOOGOMJA YOOGOMJA deleted the fix/android-cleanup-destroyed-player-crash branch October 21, 2025 06:20
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.

2 participants