Fix crash on windows when window is minimized
This commit is contained in:
		
							parent
							
								
									5cb36d0bcc
								
							
						
					
					
						commit
						6dc3697baf
					
				| 
						 | 
				
			
			@ -58,6 +58,7 @@ pub struct WindowState {
 | 
			
		|||
    pub surface_desc: wgpu::SurfaceConfiguration,
 | 
			
		||||
    pub surface: wgpu::Surface<'static>,
 | 
			
		||||
    pub hidpi_factor: f64,
 | 
			
		||||
    pub minimized: bool,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl WindowState {
 | 
			
		||||
| 
						 | 
				
			
			@ -105,6 +106,7 @@ impl WindowState {
 | 
			
		|||
            surface_desc,
 | 
			
		||||
            surface,
 | 
			
		||||
            hidpi_factor,
 | 
			
		||||
            minimized: false,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -114,9 +116,14 @@ impl WindowState {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn handle_resize(&mut self, size: &PhysicalSize<u32>) {
 | 
			
		||||
        self.surface_desc.width = size.width;
 | 
			
		||||
        self.surface_desc.height = size.height;
 | 
			
		||||
        self.surface.configure(&self.device, &self.surface_desc);
 | 
			
		||||
        if size.width > 0 && size.height > 0 {
 | 
			
		||||
            self.minimized = false;
 | 
			
		||||
            self.surface_desc.width = size.width;
 | 
			
		||||
            self.surface_desc.height = size.height;
 | 
			
		||||
            self.surface.configure(&self.device, &self.surface_desc);
 | 
			
		||||
        } else {
 | 
			
		||||
            self.minimized = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,6 +30,7 @@ pub struct GameWindow {
 | 
			
		|||
    client: EmulatorClient,
 | 
			
		||||
    input_mapper: Arc<RwLock<InputMapper>>,
 | 
			
		||||
    proxy: EventLoopProxy<UserEvent>,
 | 
			
		||||
    paused_due_to_minimize: bool,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl GameWindow {
 | 
			
		||||
| 
						 | 
				
			
			@ -165,6 +166,7 @@ impl GameWindow {
 | 
			
		|||
            client,
 | 
			
		||||
            input_mapper,
 | 
			
		||||
            proxy,
 | 
			
		||||
            paused_due_to_minimize: false,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -181,7 +183,9 @@ impl GameWindow {
 | 
			
		|||
        let frame = match window.surface.get_current_texture() {
 | 
			
		||||
            Ok(frame) => frame,
 | 
			
		||||
            Err(e) => {
 | 
			
		||||
                eprintln!("dropped frame: {e:?}");
 | 
			
		||||
                if !self.window.minimized {
 | 
			
		||||
                    eprintln!("dropped frame: {e:?}");
 | 
			
		||||
                }
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
| 
						 | 
				
			
			@ -325,7 +329,18 @@ impl AppWindow for GameWindow {
 | 
			
		|||
    fn handle_event(&mut self, event_loop: &ActiveEventLoop, event: &Event<UserEvent>) {
 | 
			
		||||
        match event {
 | 
			
		||||
            Event::WindowEvent { event, .. } => match event {
 | 
			
		||||
                WindowEvent::Resized(size) => self.window.handle_resize(size),
 | 
			
		||||
                WindowEvent::Resized(size) => {
 | 
			
		||||
                    self.window.handle_resize(size);
 | 
			
		||||
                    if self.window.minimized {
 | 
			
		||||
                        if self.client.is_running() {
 | 
			
		||||
                            self.client.send_command(EmulatorCommand::Pause);
 | 
			
		||||
                            self.paused_due_to_minimize = true;
 | 
			
		||||
                        }
 | 
			
		||||
                    } else if self.paused_due_to_minimize {
 | 
			
		||||
                        self.client.send_command(EmulatorCommand::Resume);
 | 
			
		||||
                        self.paused_due_to_minimize = false;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                WindowEvent::CloseRequested => event_loop.exit(),
 | 
			
		||||
                WindowEvent::RedrawRequested => self.draw(event_loop),
 | 
			
		||||
                _ => (),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,7 +73,9 @@ impl InputWindow {
 | 
			
		|||
        let frame = match window.surface.get_current_texture() {
 | 
			
		||||
            Ok(frame) => frame,
 | 
			
		||||
            Err(e) => {
 | 
			
		||||
                eprintln!("dropped frame: {e:?}");
 | 
			
		||||
                if !self.window.minimized {
 | 
			
		||||
                    eprintln!("dropped frame: {e:?}");
 | 
			
		||||
                }
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue