From 76643dce946f70cff1dd4082835a59b80b2a8739 Mon Sep 17 00:00:00 2001 From: javalsai Date: Sat, 30 May 2026 04:50:12 +0200 Subject: [PATCH] fix: panic on empty leaderboards --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index d10a178..c5de6f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,7 +118,7 @@ fn handle_hiscores(rx: mpsc::Receiver<(Entry, Leaderboard)>, hiscores_arc: Arc { let mut hiscores = hiscores_arc.lock().unwrap(); - if new_entry.score > hiscores[19].score { + if hiscores.get(19).is_none_or(|hiscore| new_entry.score > hiscore.score) { println!("New hiscore {new_entry:?}"); hiscores.push(new_entry); hiscores.sort(); @@ -134,7 +134,7 @@ fn handle_hiscores(rx: mpsc::Receiver<(Entry, Leaderboard)>, hiscores_arc: Arc { let mut loscores = loscores_arc.lock().unwrap(); - if new_entry.score > loscores[19].score { + if loscores.get(19).is_none_or(|loscore| new_entry.score > loscore.score) { println!("New loscore {new_entry:?}"); loscores.push(new_entry); loscores.sort();