From 37d0adb2e2aa0f014ff10aa123673f0f8283bdc1 Mon Sep 17 00:00:00 2001 From: Yakov Borevich Date: Thu, 3 Aug 2023 12:23:08 +0200 Subject: [PATCH] [core.relation] Fix bug when same multiply connection systems was added Not cpu do not leak over time when adding new connections --- crates/belly_core/src/relations/mod.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/belly_core/src/relations/mod.rs b/crates/belly_core/src/relations/mod.rs index c31e556..4152cc5 100644 --- a/crates/belly_core/src/relations/mod.rs +++ b/crates/belly_core/src/relations/mod.rs @@ -184,21 +184,19 @@ impl BindingSystemsInternal { TypeId::of::(), TypeId::of::(), ); - if self.watchers.read().unwrap().contains(&watcher) { - return; - } - { - let watchers = self.watchers.write().unwrap(); - if watchers.contains(&watcher) { - return; + if !self.watchers.read().unwrap().contains(&watcher) { + let mut watchers = self.watchers.write().unwrap(); + if !watchers.contains(&watcher) { + watchers.insert(watcher); + self.system_queue + .write() + .unwrap() + .push(Box::new(move |schedule| { + schedule.add_systems( + bind::watch_changes::.in_set(RelationsSystemSet::Changes), + ); + })); } - self.system_queue - .write() - .unwrap() - .push(Box::new(|schedule| { - schedule - .add_systems(bind::watch_changes::.in_set(RelationsSystemSet::Changes)); - })); } if self.systems.read().unwrap().contains(&entry) {