Skip to content

Commit

Permalink
[core.relation] Fix bug when same multiply connection systems was added
Browse files Browse the repository at this point in the history
Not cpu do not leak over time when adding new connections
  • Loading branch information
jkb0o committed Aug 3, 2023
1 parent 2029df8 commit 37d0adb
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions crates/belly_core/src/relations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,19 @@ impl BindingSystemsInternal {
TypeId::of::<S>(),
TypeId::of::<T>(),
);
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::<R>.in_set(RelationsSystemSet::Changes),
);
}));
}
self.system_queue
.write()
.unwrap()
.push(Box::new(|schedule| {
schedule
.add_systems(bind::watch_changes::<R>.in_set(RelationsSystemSet::Changes));
}));
}

if self.systems.read().unwrap().contains(&entry) {
Expand Down

0 comments on commit 37d0adb

Please sign in to comment.