[iOS][Android] New backend: disposing one RiveFile removes a referenced font from every other live file with the same asset name

Đang mở
#461 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

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
Lĩnh vực
backend, mobile

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-native 0.5.11, new backend (no USE_RIVE_LEGACY). The same code is on main and 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-webgl2 with a per-file assetLoader) 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>
  );
}
  1. Launch. The first label draws its text.
  2. Tap Mount second. Both labels draw their text.
  3. 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.
  4. 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:
    • registerAsset calls worker.removeGlobalFontAsset(name), then decodes, then calls addGlobalFontAsset(font, name:).
    • RegisteredAsset.release(on:), which HybridRiveFile.dispose() calls, runs removeGlobalFontAsset(name) unconditionally.
  • Android, android/src/new/.../AssetLoader.kt:
    • registerAsset calls riveWorker.unregisterFont(name) before FontAsset.fromBytes and register(name).
    • RegisteredAsset.release() calls asset.unregister(name) and asset.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.
    • deleteFont does the same for every name backed by the deleted handle.
    • addFontFileAsset re-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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rive-app/rive-nitro-react-native

Tất cả issue của rive-app/rive-nitro-react-native

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.