fix(android): prevent IllegalStateException in cleanup on destroyed p…#23
Merged
theashraf merged 1 commit intoLottieFiles:mainfrom Oct 21, 2025
Conversation
…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).
|
theashraf
approved these changes
Oct 21, 2025
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐛 Problem
The app crashes with
IllegalStateException: DotLottiePlayer object has already been destroyedwhen a component containingDotLottieis 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:
DotLottiePlayerobject gets destroyedonDetachedFromWindow()triggerscleanup()cleanup()attempts to callstop()on the already destroyed playerIllegalStateException✅ 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