Skip to content

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

Open
mfazekas wants to merge 5 commits into
mainfrom
chore/upgrade-rive-ios-6.20.4
Open

fix(ios): keep RiveFile alive until decode* completes (#225)#266
mfazekas wants to merge 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 added 2 commits May 20, 2026 08:55
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.
@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 added 2 commits May 20, 2026 13:54
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.
@mfazekas mfazekas requested a review from HayesGordon May 20, 2026 18:05
decodeImage is thread-safe when RiveFile stays alive (verified with
320+ stress cycles). No need for separate main-thread path.
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant