git clone https://garage44.eu/jeroen/cartopolis.gitcartopolis-agent · 2026-11-30T19:15:11Z
fix(app): switching a data layer redrew the tab inside its own borrow Mounted::sync walked the data layers' switches while holding the map they live in; a switch set from the resource redraws the Data tab, which looks its switches up in that same map, and the RefCell panicked. The first capture with every layer on found it. The switches are cloned out before the walk.
crates/cartopolis/src/systems/gui/lib_layers.rs | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/crates/cartopolis/src/systems/gui/lib_layers.rs b/crates/cartopolis/src/systems/gui/lib_layers.rs
index 796bcca6..e1184465 100644
--- a/crates/cartopolis/src/systems/gui/lib_layers.rs
+++ b/crates/cartopolis/src/systems/gui/lib_layers.rs
@@ -399,7 +399,16 @@ impl Mounted {
let mut changed = false;
// The data layers' switches, made as their tiles draw: a switch moved
// writes the resource, a resource moved (the MCP, a restore) the switch.
- for (id, sig) in self.l.feed_on.borrow().iter() {
+ // Cloned out first: setting a switch redraws the Data tab, which may
+ // make a switch of its own in the same map.
+ let switches: Vec<(String, Signal<bool>)> = self
+ .l
+ .feed_on
+ .borrow()
+ .iter()
+ .map(|(id, sig)| (id.clone(), sig.clone()))
+ .collect();
+ for (id, sig) in &switches {
let s = sig.get();
let last = self.last_feeds.get(id).copied().unwrap_or(false);
let field = dl.feeds.get(id).copied().unwrap_or(false);