[iOS][Android] New backend: disposing one RiveFile removes a referenced font from every other live file with the same asset name
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- android, ios, react-native, typescript
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 159
- Fork
- 17
- Merge trung bình
- 2 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 24
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rive-app/rive-nitro-react-native
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
rive-app/rive-nitro-react-native#467 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
useDisposableMemo disposes native objects in effect cleanup, so a subtree hidden by React <Activity> crashes in release builds when shown againCó thể đã có người làm @mfazekas đã nhận 10 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
rive-app/rive-nitro-react-native#448 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
android bug enhancement iOS
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 44/100
rive-app/rive-nitro-react-native#445 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
rive-app/rive-nitro-react-native#424 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement iOS
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
rive-app/rive-nitro-react-native#58 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rive-app/rive-nitro-react-native
Issue tương tự
-
status/need-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
google-gemini/gemini-cli#30328 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[hooks] SessionStart injects the knowledge-update frontmatter on a CRLF checkoutCó thể đã có người làm @abhiramshaji-cyber đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
vercel/vercel-plugin#429 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
severity:medium triage:confirmed triage:in-progress triage:reproduced
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Cotal-AI/Cotal#7231 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
boxlite-ai/boxlite#2777 ·
Maintainer thường phản hồi trong vòng 1 ngày