Skip to content

fix(ios): keep RiveFile alive until decode* completes (#225)#266

Merged
mfazekas merged 5 commits into
mainfrom
chore/upgrade-rive-ios-6.20.4
May 28, 2026
Merged

fix(ios): keep RiveFile alive until decode* completes (#225)#266
mfazekas merged 5 commits into
mainfrom
chore/upgrade-rive-ios-6.20.4

Conversation

@mfazekas
Copy link
Copy Markdown
Collaborator

@mfazekas mfazekas commented May 20, 2026

Fixes #225.

The crash was a use-after-free: RiveFile deallocated while asset downloads are in-flight, leaving RiveFactory with a dangling rive::Factory* pointer. Concurrent downloads widened the timing window, making it look like a threading race.

Fix: strong self capture in decode closures keeps activeFileRef (and thus RiveFile/RenderContext) alive until decode completes. All decode types use a background serial queue via a decodeAndApply helper.

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.

@mfazekas mfazekas changed the title chore(ios): upgrade rive-ios SDK from 6.18.2 to 6.20.4 fix(ios): serialize RiveFactory decode calls to prevent EXC_BAD_ACCESS (#225) May 20, 2026
@mfazekas mfazekas requested a review from HayesGordon May 20, 2026 18:05
@mfazekas mfazekas changed the title fix(ios): serialize RiveFactory decode calls to prevent EXC_BAD_ACCESS (#225) fix(ios): keep RiveFile alive until decode* completes (#225) May 22, 2026
@mfazekas mfazekas force-pushed the chore/upgrade-rive-ios-6.20.4 branch from 0e13390 to a985211 Compare May 27, 2026 05:01
Copy link
Copy Markdown
Contributor

@HayesGordon HayesGordon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mfazekas mfazekas enabled auto-merge (squash) May 27, 2026 11:09
@mfazekas mfazekas force-pushed the chore/upgrade-rive-ios-6.20.4 branch from a985211 to 8010a22 Compare May 27, 2026 11:09
mfazekas added 5 commits May 28, 2026 07:32
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.
@mfazekas mfazekas force-pushed the chore/upgrade-rive-ios-6.20.4 branch from 8010a22 to 8040747 Compare May 28, 2026 05:32
@mfazekas mfazekas merged commit e5a5ce4 into main May 28, 2026
9 checks passed
@mfazekas mfazekas deleted the chore/upgrade-rive-ios-6.20.4 branch May 28, 2026 05:58
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants