fix(ios): keep RiveFile alive until decode* completes (#225)#266
Merged
Conversation
0e13390 to
a985211
Compare
a985211 to
8010a22
Compare
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.
8010a22 to
8040747
Compare
mfazekas
pushed a commit
that referenced
this pull request
May 29, 2026
🤖 I have created a release *beep* *boop* --- ## [0.4.10](v0.4.9...v0.4.10) (2026-05-28) ### Bug Fixes * **android:** allow overriding CMake version for Windows long-path builds ([#265](#265)) ([7300001](7300001)) * bump iOS runtime to 6.20.4 ([#271](#271)) ([3748643](3748643)) * **ios:** keep RiveFile alive until decode* completes ([#225](#225)) ([#266](#266)) ([e5a5ce4](e5a5ce4)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
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.