fix: panic on empty leaderboards
This commit is contained in:
+2
-2
@@ -118,7 +118,7 @@ fn handle_hiscores(rx: mpsc::Receiver<(Entry, Leaderboard)>, hiscores_arc: Arc<M
|
||||
Ok((new_entry,Leaderboard::Hiscores)) =>
|
||||
{
|
||||
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<M
|
||||
Ok((new_entry,Leaderboard::Loscores)) =>
|
||||
{
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user