Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant image updating crashes the application on Android 7.x and older versions #7183

Closed
wuwbobo2021 opened this issue Dec 20, 2024 · 1 comment

Comments

@wuwbobo2021
Copy link
Contributor

wuwbobo2021 commented Dec 20, 2024

It is caused by JNI local reference overflow: get_view_rect in internal/backends/android-activity/javahelper.rs. However, there might be more potential problems. High RAM usage might occur in some other applications on newer Android versions.

Reference: rust-mobile/android-activity#173, https://developer.android.com/training/articles/perf-jni#unsupported-featuresbackwards-compatibility. "In Android versions prior to Android 8.0, the number of local references is capped at a version-specific limit. Beginning in Android 8.0, Android supports unlimited local references."

I do know how to fix the problem, but I am not sure if the jni-min-helper crate can be introduced as a dependency of i-slint-backend-android-activity.

Test case (it crashes on Android 6.0/7.0 in a few seconds):

[package]
name = "slint-test"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
slint = { version = "1.9.0", features = ["backend-android-activity-06"] }

[lib]
crate-type = ["cdylib"]
path = "lib.rs"
#[no_mangle]
fn android_main(app: slint::android::AndroidApp) {
    slint::android::init(app).unwrap();

    slint::slint!{
        export component MainWindow inherits Window {
            in property <image> screen_image;
            Image {
                source: screen_image;
           }
        }
    }
    
    let window = MainWindow::new().unwrap();

    let window_weak = window.as_weak();
    let timer = slint::Timer::default();
    timer.start(slint::TimerMode::Repeated, std::time::Duration::from_millis(1), move || {
        // image creation process is removed in this minimal test program
        let pixel_buffer = slint::SharedPixelBuffer::<slint::Rgba8Pixel>::new(320, 240);
        let img = slint::Image::from_rgba8_premultiplied(pixel_buffer);
        window_weak.upgrade().unwrap().set_screen_image(img);
    });

    window.run().unwrap();
}
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115] JNI ERROR (app bug): local reference table overflow (max=512)
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115] local reference table dump:
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]   Last 10 entries (of 511):
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       510: 0x12db2b20 android.graphics.Rect
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       509: 0x12db2b00 android.graphics.Rect
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       508: 0x12db2ae0 android.graphics.Rect
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       507: 0x12db2ac0 android.graphics.Rect
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       506: 0x12db2aa0 android.graphics.Rect
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       505: 0x12db2a80 android.graphics.Rect
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       504: 0x12db2a60 android.graphics.Rect
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       503: 0x12db2a40 android.graphics.Rect
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       502: 0x12db2a20 android.graphics.Rect
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       501: 0x12db2a00 android.graphics.Rect
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]   Summary:
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]         1 of dalvik.system.DexClassLoader
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]         1 of SlintAndroidJavaHelper
12-20 21:15:43.347 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]         4 of java.lang.Class (4 unique instances)
12-20 21:15:43.348 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]         6 of java.lang.String (6 unique instances)
12-20 21:15:43.348 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]         1 of dalvik.system.PathClassLoader
12-20 21:15:43.348 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]         1 of java.io.FileOutputStream
12-20 21:15:43.348 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]         1 of java.nio.DirectByteBuffer
12-20 21:15:43.348 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]         1 of byte[] (16064 elements)
12-20 21:15:43.348 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]       492 of android.graphics.Rect (492 unique instances)
12-20 21:15:43.348 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115]         3 of java.io.File (3 unique instances)
12-20 21:15:43.348 24093 24107 F art     : art/runtime/indirect_reference_table.cc:115] 

Besides, the virtual keyboard always prompt out on startup, maybe calling show_or_hide_soft_input(false) for once can fix the problem; the default material Slint style on Android currently features a pink color theme, which has nothing to do with the original material design style. It means a bad first impression for some people.

PS: docs.rs failed to build slint crate documentation because api/rs/slint/docs symbolic link has been deleted (commit e45e699). Would it be fixed?

@ogoffart
Copy link
Member

Duplicate of #7182

@ogoffart ogoffart marked this as a duplicate of #7182 Dec 21, 2024
@ogoffart ogoffart closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants