fix(ios): keep RiveFile alive until decode* completes (#225)#266
Open
mfazekas wants to merge 5 commits into
Open
fix(ios): keep RiveFile alive until decode* completes (#225)#266mfazekas wants to merge 5 commits into
mfazekas wants to merge 5 commits into
Conversation
Includes render context retain fix, race condition fixes, and concurrency improvements that should address #225.
#225) RiveFactory.decodeImage/decodeFont/decodeAudio are not thread-safe. Using DispatchQueue.global (concurrent) caused crashes when multiple assets decoded simultaneously. Replaced with a dedicated serial queue.
decodeImage runs through RenderContext which is not thread-safe and races with beginFrame/endFrame on the main thread. Move it to run synchronously within the existing MainActor context. For font/audio (thread-safe), keep background decode but capture self strongly so the ReferencedAssetLoader (and its activeFileRef) stays alive until the dispatch completes.
decodeImage is thread-safe when RiveFile stays alive (verified with 320+ stress cycles). No need for separate main-thread path.
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.
Fixes #225.
The crash was a use-after-free:
RiveFiledeallocated while asset downloads are in-flight, leavingRiveFactorywith a danglingrive::Factory*pointer. Concurrent downloads widened the timing window, making it look like a threading race.Fix: strong
selfcapture in decode closures keepsactiveFileRef(and thusRiveFile/RenderContext) alive until decode completes. All decode types use a background serial queue via adecodeAndApplyhelper.Also upgrades rive-ios from 6.18.2 to 6.20.4 (includes CDN use-after-free fix from rive-app/rive-ios#449).
Verified with 320+ mount/unmount stress cycles without crash.