From 64ad4466348d5688b6bea5b60f019d9a59d656ab Mon Sep 17 00:00:00 2001
From: Felix Wiegand <felix-wiegand@protonmail.ch>
Date: Sat, 25 Nov 2023 20:26:37 +0100
Subject: [PATCH 1/2] Prevent panic in case tiles channel fills up

- Make download thread wait for channel capacity
- Do not panic in main thread in case download thread dies, to avoid
  crashing the entire application
---
 walkers/src/download.rs | 4 ++--
 walkers/src/tiles.rs    | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/walkers/src/download.rs b/walkers/src/download.rs
index 33a82d14..04715f73 100644
--- a/walkers/src/download.rs
+++ b/walkers/src/download.rs
@@ -1,5 +1,5 @@
 use egui::Context;
-use futures::StreamExt;
+use futures::{SinkExt, StreamExt};
 use image::ImageError;
 use reqwest::header::USER_AGENT;
 
@@ -59,7 +59,7 @@ where
 
         match download_and_decode(&client, &url, &egui_ctx).await {
             Ok(tile) => {
-                tile_tx.try_send((request, tile)).map_err(|_| ())?;
+                tile_tx.send((request, tile)).await.map_err(|_| ())?;
                 egui_ctx.request_repaint();
             }
             Err(e) => {
diff --git a/walkers/src/tiles.rs b/walkers/src/tiles.rs
index dd0fee45..83df4b2d 100644
--- a/walkers/src/tiles.rs
+++ b/walkers/src/tiles.rs
@@ -111,7 +111,9 @@ impl Tiles {
             Err(_) => {
                 // Just ignore. It means that no new tile was downloaded.
             }
-            Ok(None) => panic!("IO thread is dead"),
+            Ok(None) => {
+                log::error!("IO thread is dead")
+            }
         }
 
         match self.cache.entry(tile_id) {

From fd4b7fed44bcf3aafc431ad4457aa0a7062ee2a7 Mon Sep 17 00:00:00 2001
From: Felix Wiegand <felix-wiegand@protonmail.ch>
Date: Sat, 25 Nov 2023 20:27:47 +0100
Subject: [PATCH 2/2] Only process scroll-by-wheel when pointer is over map

---
 walkers/src/map.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/walkers/src/map.rs b/walkers/src/map.rs
index 4579cde4..affa1f34 100644
--- a/walkers/src/map.rs
+++ b/walkers/src/map.rs
@@ -96,7 +96,7 @@ impl Map<'_, '_> {
 
         // Zooming and dragging need to be exclusive, otherwise the map will get dragged when
         // pinch gesture is used.
-        if !(0.99..=1.01).contains(&zoom_delta) {
+        if !(0.99..=1.01).contains(&zoom_delta) && ui.ui_contains_pointer() {
             // Displacement of mouse pointer relative to widget center
             let offset = response.hover_pos().map(|p| p - response.rect.center());