[iOS][Android] New backend: disposing one RiveFile removes a referenced font from every other live file with the same asset name
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- android, ios, react-native, typescript
Direzione di ricerca
Read ios/new/AssetLoader.swift, the Android AssetLoader.kt under android/src/new, and the referenced runtime behavior in command_server.cpp. Trace how registering and releasing shared assets affects live files, including the font-handle lifetime on Android; then check the same behavior for images and audio. Done means disposing one file leaves assets available to other live files, and registration does not temporarily clear them.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
With the new (default) runtime backend, every asset passed through referencedAssets is registered on the shared worker globally under its name. When a file is disposed, it unregisters that name. The worker applies a name's asset to every loaded file, and unregistering the name clears it in all of them. So when two files reference the same out-of-band font (the same .riv, or two .riv files exported with the same font asset), unmounting one leaves the other with no font: its text runs draw nothing, while its shapes still draw.
We hit this in a production app. A Rive speech bubble stays mounted on the home screen. A reward screen that uses the same referenced font is pushed over it and then popped. Text set on the bubble afterwards never draws.
Environment
@rive-app/react-native0.5.11, new backend (noUSE_RIVE_LEGACY). The same code is onmainand in 0.5.13, whose only changes are the Android SDK bumps.- rive-ios 6.29.0, rive-android 11.14.3
- React Native 0.86.2, Expo SDK 57, react-native-nitro-modules 0.35.10
- Reproduced on the iOS 26.5 simulator (iPhone 17 Pro, Release build). Seen on Android too.
- Web (
@rive-app/react-webgl2with a per-fileassetLoader) is not affected.
Reproduction
Take a .riv with a text run whose font is exported as Referenced (not embedded). FONT below is the asset's unique name, as rive-gen-types prints it (for example Inter-4228759).
import { useState } from 'react';
import { Button, View } from 'react-native';
import { RiveView, useRiveFile } from '@rive-app/react-native';
const FONT = 'Inter-4228759';
const ASSETS = { [FONT]: { source: require('./Inter.ttf'), type: 'font' as const } };
function Label() {
const { riveFile } = useRiveFile(require('./label.riv'), { referencedAssets: ASSETS });
return riveFile ? <RiveView file={riveFile} autoPlay style={{ height: 120 }} /> : null;
}
export default function Repro() {
const [second, setSecond] = useState(false);
return (
<View style={{ flex: 1, paddingTop: 80 }}>
<Label />
{second ? <Label /> : null}
<Button title={second ? 'Unmount second' : 'Mount second'} onPress={() => setSecond((on) => !on)} />
</View>
);
}
- Launch. The first label draws its text.
- Tap Mount second. Both labels draw their text.
- Tap Unmount second. The first label loses its font. Its text draws nothing from the next frame that shapes it, for example after its text changes through data binding or a state change. Its shapes keep drawing.
- Tap Mount second again. Registering the name again re-applies the font to the first label as well.
The steps we ran in our app have the same shape: file A mounted, file B with the same referenced font mounted and then disposed, then A's text set through a view model. A's text did not draw. In a control run without file B, it drew every time.
The snippet above is the same pattern reduced to its parts. We have not run it as a standalone app.
Expected
Disposing a file releases only that file's hold on a referenced asset. Other live files keep drawing with it.
Actual
Disposing any file that registered the name removes the asset from all live files.
Cause
- iOS,
ios/new/AssetLoader.swift:registerAssetcallsworker.removeGlobalFontAsset(name), then decodes, then callsaddGlobalFontAsset(font, name:).RegisteredAsset.release(on:), whichHybridRiveFile.dispose()calls, runsremoveGlobalFontAsset(name)unconditionally.
- Android,
android/src/new/.../AssetLoader.kt:registerAssetcallsriveWorker.unregisterFont(name)beforeFontAsset.fromBytesandregister(name).RegisteredAsset.release()callsasset.unregister(name)andasset.close().close()deletes the font handle. If that handle is the one currently backing the name, deleting it also unregisters the name.
- rive-runtime
command_server.cpp, shared by both:removeFontFileAsset→removeFont(name)+applyFont(name, nullptr)clears the font in every loaded file asset with that name.deleteFontdoes the same for every name backed by the deleted handle.addFontFileAssetre-applies the font to all of them, which is why step 4 recovers.
The remove-then-decode-then-add order in registerAsset also clears the name in every other live file for as long as the decode takes, whenever a new file registers it. The same applies to images and audio.
Suggested fix
Count holders per (type, name) in AssetLoader, and remove the name only when the last file holding it is disposed.
Register by replacing in place. addGlobal*Asset and register(name) already replace the name's resource (setResource overwrites it, and the worker swaps its dictionary entry), so the remove before the decode is not needed.
On Android, also keep the asset that currently backs a name open until it is replaced or its name is released, since closing it unregisters the name.
Happy to open a PR with this.
Workaround
Give every .riv its own font asset id: import the font into each file separately instead of copying it from another file. Then no two live files share a name. The same file mounted twice still collides.
Nothing in the public API helps here. updateReferencedAssets is not supported on the new backend.
- Lingua principale
- TypeScript
- Stelle
- 159
- Fork
- 17
- Merge medio
- 2g 15h
- PR unite (30g)
- 24
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rive-app/rive-nitro-react-native
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
rive-app/rive-nitro-react-native#467 ·
I maintainer di solito rispondono entro 1 giorno
-
useDisposableMemo disposes native objects in effect cleanup, so a subtree hidden by React <Activity> crashes in release builds when shown againForse già presa @mfazekas l’ha presa 10 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
rive-app/rive-nitro-react-native#448 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
android bug enhancement iOS
Difficoltà 5/5 Più di una settimana Idoneità per principianti 44/100
rive-app/rive-nitro-react-native#445 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
rive-app/rive-nitro-react-native#424 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement iOS
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
rive-app/rive-nitro-react-native#58 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rive-app/rive-nitro-react-native
Issue simili
-
status/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
google-gemini/gemini-cli#30328 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[hooks] SessionStart injects the knowledge-update frontmatter on a CRLF checkoutForse già presa @abhiramshaji-cyber l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
vercel/vercel-plugin#429 ·
I maintainer di solito rispondono entro 1 giorno
-
severity:medium triage:confirmed triage:in-progress triage:reproduced
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
Cotal-AI/Cotal#7231 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
boxlite-ai/boxlite#2777 ·
I maintainer di solito rispondono entro 1 giorno