Repository: iced-rs/iced (language: rust)

Issue:
tiny_skia backend panics if you have an Combobox menu with zero search results
### Is there an existing issue for this?

- [X] I have searched the existing issues.

### Is this issue related to iced?

- [X] My hardware is compatible and my graphics drivers are up-to-date.

### What happened?

- Run the Combobox example with tiny-skia backend
```sh
ICED_BACKEND=tiny-skia cargo r
```
- Write "ee" into the combobox text field
- The application panics with:
```
thread 'main' panicked at tiny_skia/src/backend.rs:162:17:
Quad with non-normal height!
```

### What is the expected behavior?

The application should not panic even if there are no results in the combobox menu.

### Version

master

### Operating System

Linux

### Do you have any log output?

```shell
> RUST_BACKTRACE=1 ICED_BACKEND=tiny-skia cargo r
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `/local/home/blazekra/data/git/iced/target/debug/combo_box`
thread 'main' panicked at tiny_skia/src/backend.rs:162:17:
Quad with non-normal height!
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: iced_tiny_skia::backend::Backend::draw_primitive
             at /local/home/blazekra/data/git/iced/tiny_skia/src/backend.rs:162:17
   3: iced_tiny_skia::backend::Backend::draw_primitive
             at /local/home/blazekra/data/git/iced/tiny_skia/src/backend.rs:700:21
   4: iced_tiny_skia::backend::Backend::draw_primitive
             at /local/home/blazekra/data/git/iced/tiny_skia/src/backend.rs:748:21
   5: iced_tiny_skia::backend::Backend::draw
             at /local/home/blazekra/data/git/iced/tiny_skia/src/backend.rs:103:17
   6: iced_tiny_skia::window::compositor::present
             at /local/home/blazekra/data/git/iced/tiny_skia/src/window/compositor.rs:202:5
   7: <iced_renderer::compositor::Compositor as iced_graphics::compositor::Compositor>::present::{{closure}}
             at /local/home/blazekra/data/git/iced/renderer/src/compositor.rs:118:17
   8: iced_graphics::renderer::Renderer<B>::with_primitives
             at /local/home/blazekra/data/git/iced/graphics/src/renderer.rs:56:9
   9: <iced_renderer::compositor::Compositor as iced_graphics::compositor::Compositor>::present
             at /local/home/blazekra/data/git/iced/renderer/src/compositor.rs:117:18
  10: iced_winit::application::run_instance::{{closure}}
             at /local/home/blazekra/data/git/iced/winit/src/application.rs:458:23
  11: iced_winit::application::run::{{closure}}
             at /local/home/blazekra/data/git/iced/winit/src/application.rs:228:24
  12: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:294:13
  13: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:294:13
  14: winit::platform_impl::platform::wayland::event_loop::EventLoop<T>::single_iteration
             at /local/home/blazekra/.cargo/git/checkouts/winit-57d3141eaf559308/b91e39e/src/platform_impl/linux/wayland/event_loop/mod.rs:504:17
  15: winit::platform_impl::platform::wayland::event_loop::EventLoop<T>::poll_events_with_timeout
             at /local/home/blazekra/.cargo/git/checkouts/winit-57d3141eaf559308/b91e39e/src/platform_impl/linux/wayland/event_loop/mod.rs:323:9
  16: winit::platform_impl::platform::wayland::event_loop::EventLoop<T>::pump_events
             at /local/home/blazekra/.cargo/git/checkouts/winit-57d3141eaf559308/b91e39e/src/platform_impl/linux/wayland/event_loop/mod.rs:237:13
  17: winit::platform_impl::platform::wayland::event_loop::EventLoop<T>::run_on_demand
             at /local/home/blazekra/.cargo/git/checkouts/winit-57d3141eaf559308/b91e39e/src/platform_impl/linux/wayland/event_loop/mod.rs:201:19
  18: winit::platform_impl::platform::EventLoop<T>::run_on_demand
             at /local/home/blazekra/.cargo/git/checkouts/winit-57d3141eaf559308/b91e39e/src/platform_impl/linux/mod.rs:821:56
  19: winit::platform_impl::platform::EventLoop<T>::run
             at /local/home/blazekra/.cargo/git/checkouts/winit-57d3141eaf559308/b91e39e/src/platform_impl/linux/mod.rs:814:9
  20: winit::event_loop::EventLoop<T>::run
             at /local/home/blazekra/.cargo/git/checkouts/winit-57d3141eaf559308/b91e39e/src/event_loop.rs:249:9
  21: iced_winit::application::run
             at /local/home/blazekra/data/git/iced/winit/src/application.rs:243:13
  22: iced::application::Application::run
             at /local/home/blazekra/data/git/iced/src/application.rs:208:12
  23: iced::sandbox::Sandbox::run
             at /local/home/blazekra/data/git/iced/src/sandbox.rs:153:9
  24: combo_box::main
             at ./src/main.rs:7:5
  25: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```



Discussion / hints:

Fix patch:
diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs
index e4f4a41fb1..253850dffe 100644
--- a/widget/src/combo_box.rs
+++ b/widget/src/combo_box.rs
@@ -700,38 +700,47 @@ where
                 ..
             } = tree.state.downcast_mut::<Menu<T>>();
 
-            let bounds = layout.bounds();
-
             self.state.sync_filtered_options(filtered_options);
 
-            let mut menu = menu::Menu::new(
-                menu,
-                &filtered_options.options,
-                hovered_option,
-                |x| {
-                    tree.children[0]
-                        .state
-                        .downcast_mut::<text_input::State<Renderer::Paragraph>>(
-                        )
-                        .unfocus();
-
-                    (self.on_selected)(x)
-                },
-                self.on_option_hovered.as_deref(),
-                &self.menu_class,
-            )
-            .width(bounds.width)
-            .padding(self.padding);
-
-            if let Some(font) = self.font {
-                menu = menu.font(font);
-            }
+            if filtered_options.options.is_empty() {
+                None
+            } else {
+                let bounds = layout.bounds();
+
+                let mut menu = menu::Menu::new(
+                    menu,
+                    &filtered_options.options,
+                    hovered_option,
+                    |x| {
+                        tree.children[0]
+                    .state
+                    .downcast_mut::<text_input::State<Renderer::Paragraph>>(
+                    )
+                    .unfocus();
+
+                        (self.on_selected)(x)
+                    },
+                    self.on_option_hovered.as_deref(),
+                    &self.menu_class,
+                )
+                .width(bounds.width)
+                .padding(self.padding);
+
+                if let Some(font) = self.font {
+                    menu = menu.font(font);
+                }
 
-            if let Some(size) = self.size {
-                menu = menu.text_size(size);
-            }
+                if let Some(size) = self.size {
+                    menu = menu.text_size(size);
+                }
 
-            Some(menu.overlay(layout.position() + translation, bounds.height))
+                Some(
+                    menu.overlay(
+                        layout.position() + translation,
+                        bounds.height,
+                    ),
+                )
+            }
         } else {
             None
         }


Test patch: