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

Possible crashing on Android 9.0; Instant image updating crashes the application on Android 7.x and older versions #7182

Open
wuwbobo2021 opened this issue Dec 20, 2024 · 3 comments · May be fixed by #7204
Labels
a:platform-android Android platform integration (mO,bS) bug Something isn't working

Comments

@wuwbobo2021
Copy link
Contributor

wuwbobo2021 commented Dec 20, 2024

Bug Description

It is caused by JNI local reference overflow: get_view_rect in internal/backends/android-activity/javahelper.rs.

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.

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?

Reproducible Code (if applicable)

[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] 

Environment Details

  • Slint Version: 1.9.0
  • Platform/OS: Android (older than 8.0)
  • Programming Language: Rust
  • Backend/Renderer: android-activity

Product Impact

Unexpected crashing may appear here and there on Android versions prior to 8.0. High RAM usage may occur in a few specific applications on newer Android versions.

@wuwbobo2021 wuwbobo2021 added bug Something isn't working need triaging Issue that the owner of the area still need to triage labels Dec 20, 2024
@hunger hunger added the a:platform-android Android platform integration (mO,bS) label Dec 21, 2024
@ogoffart
Copy link
Member

Thanks for filing a bug report.

I'm not sure it is worth supporting Android 7 but I'd accept PR if it is not too intrusive.

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.

I think if it solves the problem, that's fine.

PS: docs.rs failed to build slint crate documentation

Thanks for pointing this out. We will try to make a new release as soon as possible (which may need to wait after the holidays)

@ogoffart ogoffart removed the need triaging Issue that the owner of the area still need to triage label Dec 21, 2024
@wuwbobo2021
Copy link
Contributor Author

wuwbobo2021 commented Dec 21, 2024

Sorry for the duplication caused by bad connection to Github.

jni-min-helper isn't a necessary component for fixing this particular issue. While it provides "convenient" ways of creating AutoLocal and calling JNIEnv::exception_clear() implicitly, it can be intrusive here as it would change all of the JNI related code. In i-slint-android-activity, exceptions are handled by print_jni_error() and panicking, and there aren't too many calls in the code that creates new JNI local references. So the problem can be solved without introducing that crate.

How about improving the material design style (currently pink)? I'll probably not do it by myself, because I'm not good at designing themes, and SLINT_STYLE=fluent env variable works well.

@wuwbobo2021 wuwbobo2021 changed the title Instant image updating crashes the application on Android 7.x and older versions Possible crashing on Android 9.0; Instant image updating crashes the application on Android 7.x and older versions Dec 24, 2024
@wuwbobo2021
Copy link
Contributor Author

wuwbobo2021 commented Dec 24, 2024

Another problem: BlendModeColorFilter in the Java helper crashes the application on Android 9.0 when a text input gets focused. (fixed by the PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:platform-android Android platform integration (mO,bS) bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants