Skip to content

Commit

Permalink
Remove event loop spamming when new event arrives (#167)
Browse files Browse the repository at this point in the history
`new_event` method is called when a new event arrives on an event loop. Putting new event (in this case `BlitzEvent::Poll`) on the same event loop from this method causes this method to be called again. This ends up spamming event loop, 100% CPU utilization on some operating systems, and makes the `poll` "spin".
  • Loading branch information
DavidHusicka authored Nov 30, 2024
1 parent c5cb7a7 commit 19c28be
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/blitz-shell/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ impl<Doc: DocumentLike> ApplicationHandler<BlitzEvent> for BlitzApplication<Doc>
}

fn new_events(&mut self, _event_loop: &ActiveEventLoop, _cause: winit::event::StartCause) {
for window_id in self.windows.keys().copied() {
_ = self.proxy.send_event(BlitzEvent::Poll { window_id });
}

#[cfg(all(feature = "menu", not(any(target_os = "android", target_os = "ios"))))]
if let Ok(event) = self.menu_channel.try_recv() {
if event.id == muda::MenuId::new("dev.show_layout") {
Expand All @@ -96,6 +92,8 @@ impl<Doc: DocumentLike> ApplicationHandler<BlitzEvent> for BlitzApplication<Doc>
if let Some(window) = self.windows.get_mut(&window_id) {
window.handle_winit_event(event);
}

let _ = self.proxy.send_event(BlitzEvent::Poll { window_id });
}

fn user_event(&mut self, _event_loop: &ActiveEventLoop, event: BlitzEvent) {
Expand Down

0 comments on commit 19c28be

Please sign in to comment.