slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.23k stars 582 forks source link

Panic in software renderer running on ESP32 when trying to open a PopupWindow #4639

Closed kristofferpeterhansel closed 1 month ago

kristofferpeterhansel commented 8 months ago

Platform

ESP32 using esp-idf (so not no_std. Although enabling std feature in slint still causes issues).

Running it locally on macOS does not display the same issue.

Description

I've been trying to get an slint UI working on an ESP32 device (M5Stack Core2 v1.1). And while it is currently quite slow - and has some touch input issues with some controls. It works well enough at least for prototyping a UI.

But a recent change in the UI seems to have started to trigger a panic with no obvious reason I can find. From inside a component I am trying to use PopupWindow to create basically a full-screen overlay for some temporary input. And it seems to have been working. Until some change started to trigger this issue. But I have so far not been able to isolate something specific that provokes it.

thread 'main' panicked at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/euclid-0.22.9/src/size.rs:323:25:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

abort() was called at PC 0x4018ce2a on core 0
0x4018ce2a - panic_abort::__rust_start_panic::abort
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/panic_abort/src/lib.rs:43

Backtrace: 0x40083b61:0x3ffc2470 0x40089905:0x3ffc2490 0x4008f511:0x3ffc24b0 0x4018ce2a:0x3ffc2520 0x4018ce1e:0x3ffc2540 0x40174e42:0x3ffc2560 0x40174df4:0x3ffc25b0 0x40173a73:0x3ffc2620 0x4017393c:0x3ffc2650 0x40174bb7:0x3ffc2670 0x4019e24c:0x3ffc26a0 0x4019e29f:0x3ffc26e0 0x40145353:0x3ffc2720 0x40144c12:0x3ffc2780 0x401432a5:0x3ffc27d0 0x4014e2cb:0x3ffc27f0 0x40146807:0x3ffc2830 0x400e522f:0x3ffc2a10 0x4013b6e7:0x3ffc2b10 0x401418be:0x3ffc2f50 0x4014191f:0x3ffc2f70 0x4014196c:0x3ffc2f90 0x4011af46:0x3ffc2fb0 0x4013bc95:0x3ffc2ff0 0x400d4462:0x3ffc30c0 0x401b85cf:0x3ffc3130 0x400d4284:0x3ffc3150 0x401732da:0x3ffc3170 0x400d4274:0x3ffc31a0 0x400d44c7:0x3ffc31d0 0x40140087:0x3ffc31f0 0x401bab2f:0x3ffc3210
0x40083b61 - panic_abort
    at /Users/kristoffer/Development/slint-test/.embuild/espressif/esp-idf/v5.1.2/components/esp_system/panic.c:452
0x3ffc2470 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x40089905 - esp_system_abort
    at /Users/kristoffer/Development/slint-test/.embuild/espressif/esp-idf/v5.1.2/components/esp_system/port/esp_system_chip.c:84
0x3ffc2490 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4008f511 - abort
    at /Users/kristoffer/Development/slint-test/.embuild/espressif/esp-idf/v5.1.2/components/newlib/abort.c:38
0x3ffc24b0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4018ce2a - panic_abort::__rust_start_panic::abort
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/panic_abort/src/lib.rs:43
0x3ffc2520 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4018ce1e - __rust_start_panic
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/panic_abort/src/lib.rs:38
0x3ffc2540 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x40174e42 - rust_panic
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/std/src/panicking.rs:831
0x3ffc2560 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x40174df4 - std::panicking::rust_panic_with_hook
    at ??:??
0x3ffc25b0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x40173a73 - std::panicking::begin_panic_handler::{{closure}}
    at ??:??
0x3ffc2620 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4017393c - std::sys_common::backtrace::__rust_end_short_backtrace
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:170
0x3ffc2650 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x40174bb7 - rust_begin_unwind
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/std/src/panicking.rs:645
0x3ffc2670 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4019e24c - core::panicking::panic_fmt
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/panicking.rs:72
0x3ffc26a0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4019e29f - core::panicking::panic
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/panicking.rs:127
0x3ffc26e0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x40145353 - euclid::rect::Rect<T,U>::cast
    at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/euclid-0.22.9/src/rect.rs:518
0x3ffc2720 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x40144c12 - i_slint_core::window::WindowInner::draw_contents::{{closure}}
    at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.4.1/window.rs:818
0x3ffc2780 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x401432a5 - i_slint_core::properties::PropertyTracker<DirtyHandler>::evaluate_as_dependency_root
    at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.4.1/properties.rs:1428
0x3ffc27d0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4014e2cb - i_slint_core::window::WindowInner::draw_contents
    at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.4.1/window.rs:827
0x3ffc27f0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x40146807 - i_slint_core::software_renderer::prepare_scene
    at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.4.1/software_renderer.rs:1124
0x3ffc2830 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x400e522f - i_slint_core::software_renderer::render_window_frame_by_line
    at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.4.1/software_renderer.rs:681
0x3ffc2a10 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4013b6e7 - <slint_test::esp32::Esp32Platform as i_slint_core::platform::Platform>::run_event_loop
    at /Users/kristoffer/Development/slint-test/src/esp32.rs:146
0x3ffc2b10 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x401418be - slint::run_event_loop::{{closure}}
    at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/slint-1.4.1/lib.rs:234
0x3ffc2f50 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4014191f - i_slint_core::context::with_platform
    at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.4.1/context.rs:60
0x3ffc2f70 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4014196c - i_slint_backend_selector::with_platform
    at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-backend-selector-1.4.1/lib.rs:136
0x3ffc2f90 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4011af46 - <slint_test::ui::slint_generatedAppWindow::AppWindow as i_slint_core::api::ComponentHandle>::run
    at /Users/kristoffer/Development/slint-test/target/xtensa-esp32-espidf/debug/build/slint-test-9872065e08ece67d/out/main.rs:21342
0x3ffc2fb0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x4013bc95 - slint_test::ui::app_main_view
    at /Users/kristoffer/Development/slint-test/src/ui/mod.rs:112
0x3ffc2ff0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x400d4462 - slint_test::main
    at /Users/kristoffer/Development/slint-test/src/main.rs:51
0x3ffc30c0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x401b85cf - core::ops::function::FnOnce::call_once
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/ops/function.rs:250
0x3ffc3130 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x400d4284 - std::rt::lang_start::{{closure}}
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/std/src/rt.rs:167
0x3ffc3150 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x401732da - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/ops/function.rs:284
0x3ffc3170 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x400d4274 - std::rt::lang_start
    at /Users/kristoffer/.rustup/toolchains/esp/lib/rustlib/src/rust/library/std/src/rt.rs:166
0x3ffc31a0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x400d44c7 - main
    at ??:??
0x3ffc31d0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x40140087 - app_main
    at /Users/kristoffer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-sys-0.34.0/src/start.rs:46
0x3ffc31f0 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
0x401bab2f - main_task
    at /Users/kristoffer/Development/slint-test/.embuild/espressif/esp-idf/v5.1.2/components/freertos/app_startup.c:208
0x3ffc3210 - _ZN12_GLOBAL__N_114emergency_poolE
    at ??:??
ogoffart commented 7 months ago

Thanks for your bug report.

It looks like it panics because it cannot convert cast() one of the rectangle in this function:

https://github.com/slint-ui/slint/blob/v1.4.1/internal/core/software_renderer.rs#L1129-L1133

It is casting between i16 and f32. So it looks like there is so this should be only a problem if we have very high values (but i guess your screen is smaller than 32767 width or height)

But it is true that we might have a problem if the code had some division by zero in the .slint code (eg https://github.com/slint-ui/slint/issues/3982) or maybe the size got too big. But I couldn't reproduce the problem with a simple app.

Do you know the size and position of your Popup?

kristofferpeterhansel commented 7 months ago

The position should be on 0 x and y. With a width of 320 and a height of 240. I'll have to double check when I get home. But I believe I even have it hard-coded here. Since there is no way to get that dimension from inside the component I make it in (that I am aware of)

kristofferpeterhansel commented 7 months ago

Haha. Looks like I made the classic mistake of over-thinking is issue.

After trying to build a simplified example for a while I came down to the one thing I didn't think it could be. Setting the max value of the Slider component to zero.

So trying to render this will consistently panic on my ESP32 device (but not on macOS):

Slider { minimum: 0; maximum: 0;}

In this case the value is calculated in the slint file based on other values. And it does make sense to not be able to select a value.

ogoffart commented 7 months ago

I can see how this Slider might cause a division by zero. But I still couldn't reproduce a crash. when i tried locally

ogoffart commented 1 month ago

closing this issue since i couldn't reproduce.