[iOS][Android] New backend: disposing one RiveFile removes a referenced font from every other live file with the same asset name
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- android, ios, react-native, typescript
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 159
- 派生
- 17
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 24
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rive-app/rive-nitro-react-native 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 65/100
rive-app/rive-nitro-react-native#467 ·
维护者通常 1 天内回复
-
useDisposableMemo disposes native objects in effect cleanup, so a subtree hidden by React <Activity> crashes in release builds when shown again可能已有人在做 @mfazekas 于 10 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
rive-app/rive-nitro-react-native#448 · 1 条评论 ·
维护者通常 1 天内回复
-
android bug enhancement iOS
难度 5/5 一周以上 新手友好度 44/100
rive-app/rive-nitro-react-native#445 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
rive-app/rive-nitro-react-native#424 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement iOS
难度 4/5 3-5 天 新手友好度 35/100
rive-app/rive-nitro-react-native#58 · 7 条评论 ·
维护者通常 1 天内回复
查看 rive-app/rive-nitro-react-native 的全部 Issue
相似的 Issue
-
status/need-triage
难度 2/5 1-3 小时 新手友好度 76/100
google-gemini/gemini-cli#30328 · 1 条评论 ·
维护者通常 1 天内回复
-
[hooks] SessionStart injects the knowledge-update frontmatter on a CRLF checkout可能已有人在做 @abhiramshaji-cyber 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
vercel/vercel-plugin#429 ·
维护者通常 1 天内回复
-
severity:medium triage:confirmed triage:in-progress triage:reproduced
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
boxlite-ai/boxlite#2777 ·
维护者通常 1 天内回复