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.55k stars 602 forks source link

Lang server crash; divide by 0 #6280

Closed rscarson closed 1 month ago

rscarson commented 1 month ago

Seems to be related to this struct. Crash occurred once I put the comma after the last field:

export struct ToolbarData  {
    //
    // Device properties
    device_name: string,
    device_status: DeviceMode,

    //
    // Sweep properties
    sweep_file: string,
    sweep_data: [[string]],
    sweep_remaining_ambient: [string],
}
thread 'main' panicked at internal\renderers\skia\itemrenderer.rs:236:17:
attempt to divide by zero
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[Info  - 3:44:45 PM] Connection to server got closed. Server will restart.
true
The Slint Language Server crashed. This is a bug. Please open an issue on https://github.com/slint-ui/slint/issues
thread 'main' panicked at internal\renderers\skia\itemrenderer.rs:236:17:
attempt to divide by zero
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[Info  - 12:22:31 PM] Connection to server got closed. Server will restart.
true
The Slint Language Server crashed. This is a bug. Please open an issue on https://github.com/slint-ui/slint/issues
tronical commented 1 month ago

Offending code:


        let src = skia_safe::IRect::from_xywh(
                skia_image.width() * fit.clip_rect.origin.x / source_size.width as i32,
                skia_image.height() * fit.clip_rect.origin.y / source_size.height as i32,
                skia_image.width() * fit.clip_rect.size.width / source_size.width as i32,
                skia_image.height() * fit.clip_rect.size.height / source_size.height as i32,
            );

Looks like a null image can cause this.

rscarson commented 1 month ago

Offending code:

        let src = skia_safe::IRect::from_xywh(
                skia_image.width() * fit.clip_rect.origin.x / source_size.width as i32,
                skia_image.height() * fit.clip_rect.origin.y / source_size.height as i32,
                skia_image.width() * fit.clip_rect.size.width / source_size.width as i32,
                skia_image.height() * fit.clip_rect.size.height / source_size.height as i32,
            );

Looks like a null image can cause this.

Makes sense, I have an image generated by a backend callback. In preview mode it would be null