diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs index 75f202e7106d504399efa0937ad0fc091e980533..35efe84e485d6914fbf79ef35a2cff9d1faeb9f8 100644 --- a/crates/gpui2/src/app.rs +++ b/crates/gpui2/src/app.rs @@ -403,7 +403,7 @@ impl AppContext { fn apply_emit_effect(&mut self, emitter: EntityId, event: Box) { self.event_listeners .clone() - .retain(&emitter, |handler| handler(&event, self)); + .retain(&emitter, |handler| handler(event.as_ref(), self)); } fn apply_focus_changed_effect(&mut self, window_id: WindowId, focused: Option) { diff --git a/crates/gpui2/src/app/entity_map.rs b/crates/gpui2/src/app/entity_map.rs index cf39a2b81f1f3576af857452d727322e9e24e4c3..04205175903148885d21609890187721b6d10716 100644 --- a/crates/gpui2/src/app/entity_map.rs +++ b/crates/gpui2/src/app/entity_map.rs @@ -100,10 +100,15 @@ impl EntityMap { } pub fn take_dropped(&mut self) -> Vec<(EntityId, AnyBox)> { - let dropped_entity_ids = mem::take(&mut self.ref_counts.write().dropped_entity_ids); + let mut ref_counts = self.ref_counts.write(); + let dropped_entity_ids = mem::take(&mut ref_counts.dropped_entity_ids); + dropped_entity_ids .into_iter() - .map(|entity_id| (entity_id, self.entities.remove(entity_id).unwrap())) + .map(|entity_id| { + ref_counts.counts.remove(entity_id); + (entity_id, self.entities.remove(entity_id).unwrap()) + }) .collect() } } @@ -212,7 +217,6 @@ impl Drop for AnyHandle { if prev_count == 1 { // We were the last reference to this entity, so we can remove it. let mut entity_map = RwLockUpgradableReadGuard::upgrade(entity_map); - entity_map.counts.remove(self.entity_id); entity_map.dropped_entity_ids.push(self.entity_id); } } diff --git a/crates/gpui2/src/app/model_context.rs b/crates/gpui2/src/app/model_context.rs index 6f88bf1aa6c6d3a974cf5259931668712313cea5..d81b113b7b660c90f401b965f83c060d72a93cbd 100644 --- a/crates/gpui2/src/app/model_context.rs +++ b/crates/gpui2/src/app/model_context.rs @@ -79,7 +79,7 @@ impl<'a, T: 'static> ModelContext<'a, T> { self.app.event_listeners.insert( handle.entity_id, Box::new(move |event, cx| { - let event = event.downcast_ref().expect("invalid event type"); + let event: &E::Event = event.downcast_ref().expect("invalid event type"); if let Some((this, handle)) = this.upgrade().zip(handle.upgrade()) { this.update(cx, |this, cx| on_event(this, handle, event, cx)); true diff --git a/crates/gpui2/src/test.rs b/crates/gpui2/src/test.rs index ffad9aab8bf573531ccda1e5be3963cad8549487..3f2697f7e3f2d2c6c44165728503b7fa1accf6e0 100644 --- a/crates/gpui2/src/test.rs +++ b/crates/gpui2/src/test.rs @@ -8,7 +8,7 @@ use std::{ pub fn run_test( mut num_iterations: u64, max_retries: usize, - test_fn: &mut (dyn RefUnwindSafe + Fn(TestDispatcher)), + test_fn: &mut (dyn RefUnwindSafe + Fn(TestDispatcher, u64)), on_fail_fn: Option, _fn_name: String, // todo!("re-enable fn_name") ) { @@ -28,7 +28,7 @@ pub fn run_test( } let result = panic::catch_unwind(|| { let dispatcher = TestDispatcher::new(StdRng::seed_from_u64(seed)); - test_fn(dispatcher); + test_fn(dispatcher, seed); }); match result {