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.73k stars 614 forks source link

Panic in draw_border_rectangle #6432

Open yanshay opened 2 months ago

yanshay commented 2 months ago

The following panic happened once (with many executions), in a relatively large app so can't provide a reproducible scenario or code, so I don't know if this is of value but in case it is:

If any additional information will help to find the root cause let me know.

====================== PANIC ======================
panicked at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/euclid-0.22.11/src/point.rs:463:25:
called `Option::unwrap()` on a `None` value

Backtrace:

0x420a7259
0x420a7259 - core::option::unwrap_failed
    at /Users/user/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/option.rs:1985
0x420f06e6
0x420f06e6 - core::option::Option<T>::unwrap
    at /Users/user/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/option.rs:935
0x420f0169
0x420f0169 - <i_slint_core::software_renderer::SceneBuilder<T> as i_slint_core::item_rendering::ItemRenderer>::draw_border_rectangle
    at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.8.0/software_renderer.rs:2257
0x420e8970
0x420e8970 - i_slint_core::properties::PropertyTracker<DirtyHandler>::evaluate
    at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.8.0/properties.rs:1451
0x420baac5
0x420baac5 - <i_slint_core::items::BasicBorderRectangle as i_slint_core::items::Item_vtable_mod::Item>::render
    at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.8.0/items.rs:393
0x420cc802
0x420cc802 - i_slint_core::items::Item_vtable_mod::ItemTO::render
    at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.8.0/items.rs:108
0x42011989
0x42011989 - i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorTO::visit_item
    at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.8.0/item_tree.rs:989
0x42019580
0x42019580 - i_slint_core::item_tree::visit_item_tree
    at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.8.0/item_tree.rs:1110
0x420cc829
0x420cc829 - i_slint_core::item_tree::ItemTree_vtable_mod::ItemTreeTO::visit_children_item
    at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.8.0/item_tree.rs:44
0x42011989
0x42011989 - i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorTO::visit_item
    at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.8.0/item_tree.rs:989
ogoffart commented 2 months ago

Thanks for filing a bug.

How big is your screen? What happens here is there is a panic when trying to convert a point from f32 to i16. Maybe the Rectangle is really big (more than 35535 pixel or so?)

yanshay commented 2 months ago

My screen is 480x320. Pretty small.

I'm rendering larger coordinates (about twice as high) and animating the y to move from one page to the other. The panic took place sometime during that animation.

The only rectangle that might be special is one that forms a circle using rounded square.

If it's in the conversion of f32 to i16, maybe it's because the f32 somehow contained a NAN?

ogoffart commented 2 months ago

If it's in the conversion of f32 to i16, maybe it's because the f32 somehow contained a NAN?

That could very well be. Maybe there is a division by zero somewhere.

yanshay commented 2 months ago

I got another panic (that already occurred in the past), during the same animation and also seems to be related to rectangle: This one came without any meaningful information in the backtrace. Maybe it's related?

====================== PANIC ======================
panicked at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-core-1.8.0/software_renderer/draw_functions.rs:295:51:
called `Result::unwrap()` on an `Err` value: ()

Backtrace:

0x420101b4
0x42024a36
0x4201ba7e
0x420a14c3
0x420ff26e
0x403791a6
yanshay commented 3 weeks ago

The panic in the first post on this thread keeps happening, any ideas what I could change in my app do to avoid it? There's a comment // FIXME gradients above that code block and indeed I'm using gradients in my app, maybe I should use gradients without borders and add borders separately?

I also noticed that software_renderer.rs changed considerably and now the panic in the updated code would be in line 1885. Maybe something in the next release was improved on that front?

ogoffart commented 3 weeks ago

Unsupported gradients will just not shown, but shouldn't cause any panic.

It would really help if one could reproduce that reliably so we can fix it.

(I've made commit b0c7ac4 that adds some debug that could help understand more what exactly is going on, So if you can run with the master branch, that would be great.)

yanshay commented 3 weeks ago

It's a large application and it happens every tens of runs after some time it runs so unfortunately I don't know where to begin searching for a reproduction.

I'll try running with the master branch and get back with results once it reoccurs.