Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition that was causing a crash in time observer #628

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jbaudanza
Copy link
Contributor

I was only able to reproduce this crash once, but I took a screenshot:

Screenshot 2024-09-15 at 5 01 46 PM

The root cause is that audioPlayer is set to nil on the react-native thread, not the main thread. So, even though we change for nil on line 338, there's no guarantee it's still not nil on line 340.

This PR will wrap the audioPlayer = nil mutation in DispatchQueue.main.async.

I also changed the time observer to keep a weak reference to self, because the apple docs state this is important to prevent a retain cycle: https://developer.apple.com/documentation/avfoundation/avplayer/1385829-addperiodictimeobserverforinterv?language=swift

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