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

Issue:
Panic in cosmic-launcher
### Is your issue REALLY a bug?

- [X] My issue is indeed a bug!
- [X] I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

### 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?

cosmic-launcher crashes when searching for certain strings, for example "screenshot".

### What is the expected behavior?

cosmic-launcher not to crash

### Version

master

### Operating System

Linux

### Do you have any log output?

```shell
Oct 26 09:30:13 alissa cosmic-session[10940]: Stack backtrace:
Oct 26 09:30:13 alissa cosmic-session[10940]:    0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
Oct 26 09:30:13 alissa cosmic-session[10940]:    1: cosmic_settings_daemon::theme::watch_theme::{{closure}}
Oct 26 09:30:13 alissa cosmic-session[10940]:    2: tokio::runtime::task::core::Core<T,S>::poll
Oct 26 09:30:13 alissa cosmic-session[10940]:    3: tokio::runtime::task::harness::Harness<T,S>::poll
Oct 26 09:30:13 alissa cosmic-session[10940]:    4: tokio::task::local::LocalSet::tick
Oct 26 09:30:13 alissa cosmic-session[10940]:    5: <tokio::task::local::RunUntil<T> as core::future::future::Future>::poll
Oct 26 09:30:13 alissa cosmic-session[10940]:    6: <core::pin::Pin<P> as core::future::future::Future>::poll
Oct 26 09:30:13 alissa cosmic-session[10940]:    7: tokio::runtime::scheduler::current_thread::Context::enter
Oct 26 09:30:13 alissa cosmic-session[10940]:    8: tokio::runtime::context::scoped::Scoped<T>::set
Oct 26 09:30:13 alissa cosmic-session[10940]:    9: tokio::runtime::scheduler::current_thread::CurrentThread::block_on
Oct 26 09:30:13 alissa cosmic-session[10940]:   10: tokio::runtime::runtime::Runtime::block_on
Oct 26 09:30:13 alissa cosmic-session[10940]:   11: cosmic_settings_daemon::main
Oct 26 09:30:13 alissa cosmic-session[10940]:   12: std::sys::backtrace::__rust_begin_short_backtrace
Oct 26 09:30:13 alissa cosmic-session[10940]:   13: std::rt::lang_start::{{closure}}
Oct 26 09:30:13 alissa cosmic-session[10940]:   14: std::rt::lang_start_internal
Oct 26 09:30:13 alissa cosmic-session[10940]:   15: main
Oct 26 09:30:13 alissa cosmic-session[10940]:   16: __libc_start_call_main
Oct 26 09:30:13 alissa cosmic-session[10940]:   17: __libc_start_main_alias_2
Oct 26 09:30:13 alissa cosmic-session[10940]:   18: _start. Will try again in 819s
Oct 26 09:31:23 alissa cosmic-session[10940]: thread 'main' panicked at core/src/slice/sort/shared/smallsort.rs:860:5:
Oct 26 09:31:23 alissa cosmic-session[10940]: user-provided comparison function does not correctly implement a total order
Oct 26 09:31:23 alissa cosmic-session[10940]: stack backtrace:
Oct 26 09:31:23 alissa cosmic-session[10940]:    0: rust_begin_unwind
Oct 26 09:31:23 alissa cosmic-session[10940]:    1: core::panicking::panic_fmt
Oct 26 09:31:23 alissa cosmic-session[10940]:    2: core::slice::sort::shared::smallsort::panic_on_ord_violation
Oct 26 09:31:23 alissa cosmic-session[10940]:    3: core::slice::sort::shared::smallsort::bidirectional_merge
Oct 26 09:31:23 alissa cosmic-session[10940]:    4: core::slice::sort::stable::quicksort::quicksort
Oct 26 09:31:23 alissa cosmic-session[10940]:    5: core::slice::sort::stable::drift::sort
Oct 26 09:31:23 alissa cosmic-session[10940]:    6: core::slice::sort::stable::driftsort_main
Oct 26 09:31:23 alissa cosmic-session[10940]:    7: iced_graphics::damage::group
Oct 26 09:31:23 alissa cosmic-session[10940]:    8: <iced_tiny_skia::window::compositor::Compositor as iced_graphics::compositor::Compositor>::present
Oct 26 09:31:23 alissa cosmic-session[10940]:    9: iced_winit::program::run_instance::{{closure}}
Oct 26 09:31:23 alissa cosmic-session[10940]:   10: iced_winit::program::run::Runner<Message,F,C>::process_event
Oct 26 09:31:23 alissa cosmic-session[10940]:   11: winit::platform_impl::linux::wayland::event_loop::EventLoop::single_iteration
Oct 26 09:31:23 alissa cosmic-session[10940]:   12: winit::platform_impl::linux::wayland::event_loop::EventLoop::run_app
Oct 26 09:31:23 alissa cosmic-session[10940]:   13: iced_winit::program::run
Oct 26 09:31:23 alissa cosmic-session[10940]:   14: cosmic::app::run_single_instance
Oct 26 09:31:23 alissa cosmic-session[10940]:   15: cosmic_launcher::app::run
Oct 26 09:31:23 alissa cosmic-session[10940]:   16: cosmic_launcher::main
Oct 26 09:31:23 alissa cosmic-session[10940]: note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Oct 26 09:31:23 alissa cosmic-session[10940]: process ' DISPLAY=:1 WAYLAND_DISPLAY=wayland-1 XDG_SESSION_TYPE=wayland WAYLAND_SOCKET=44 cosmic-launcher ' failed with code 101
Oct 26 09:31:23 alissa cosmic-session[10940]: cosmic-launcher exited with error 101
Oct 26 09:31:23 alissa cosmic-session[10940]: draining stdin receiver before restarting process
Oct 26 09:31:23 alissa cosmic-session[10940]: sleeping for 10ms before restarting process cosmic-launcher (restart 1)
Oct 26 09:31:23 alissa systemd[1768]: cosmic-launcher.scope: Consumed 7.160s CPU time, 48.6M memory peak.
Oct 26 09:31:23 alissa cosmic-session[10940]: sending 1 fds
Oct 26 09:31:23 alissa cosmic-session[10940]: restarted process ' DISPLAY=:1 WAYLAND_DISPLAY=wayland-1 XDG_SESSION_TYPE=wayland WAYLAND_SOCKET=41 cosmic-launcher ', now at 2 restarts
Oct 26 09:31:23 alissa systemd[1768]: Started cosmic-launcher.scope.
```



Discussion / hints:

Fix patch:
diff --git a/graphics/src/damage.rs b/graphics/src/damage.rs
index 17d6045195..8aa427983c 100644
--- a/graphics/src/damage.rs
+++ b/graphics/src/damage.rs
@@ -45,15 +45,12 @@ pub fn list<T>(
 /// Groups the given damage regions that are close together inside the given
 /// bounds.
 pub fn group(mut damage: Vec<Rectangle>, bounds: Rectangle) -> Vec<Rectangle> {
-    use std::cmp::Ordering;
-
     const AREA_THRESHOLD: f32 = 20_000.0;
 
     damage.sort_by(|a, b| {
         a.center()
             .distance(Point::ORIGIN)
-            .partial_cmp(&b.center().distance(Point::ORIGIN))
-            .unwrap_or(Ordering::Equal)
+            .total_cmp(&b.center().distance(Point::ORIGIN))
     });
 
     let mut output = Vec::new();


Test patch: