From f8b47ca9b691da8ead5e423f27a44936cba3b448 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Wed, 6 Nov 2024 12:11:14 +0100 Subject: [PATCH] fix crash on end of playlist apparently playlist_pos() can and will change from >0 to -1 between those two queries --- src/ui/window.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ui/window.rs b/src/ui/window.rs index 0523251..510b031 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -518,18 +518,16 @@ mod imp { } fn song(&self) -> Option { - if self.obj().playlist_pos() < 0 { - None - } else { - let song: Song = self - .obj() - .playlist_model() - .item(self.obj().playlist_pos() as u32) - .unwrap() - .dynamic_cast() - .unwrap(); - - Some(song) + match self.obj().playlist_pos() { + playlist_pos if playlist_pos < 0 => None, + playlist_pos => Some( + self.obj() + .playlist_model() + .item(playlist_pos as u32) + .unwrap() + .dynamic_cast() + .unwrap(), + ), } }