Fix runtime errors

This commit is contained in:
Nathan Sobo 2023-10-23 11:34:35 +02:00
parent 5247f217fd
commit da8919002f
7 changed files with 31 additions and 20 deletions

View file

@ -510,14 +510,12 @@ impl AppContext {
.unwrap()
}
pub fn default_global<G: 'static + Default + Sync + Send>(&mut self) -> &mut G {
pub fn default_global_mut<G: 'static + Default + Sync + Send>(&mut self) -> &mut G {
let global_type = TypeId::of::<G>();
self.push_effect(Effect::NotifyGlobalObservers { global_type });
self.globals_by_type
.insert(global_type, Box::new(G::default()));
self.globals_by_type
.get_mut(&global_type)
.unwrap()
.entry(global_type)
.or_insert_with(|| Box::new(G::default()))
.downcast_mut::<G>()
.unwrap()
}