diff --git a/agent/src/capture/dxgi.rs b/agent/src/capture/dxgi.rs index 3562d99..c455a78 100644 --- a/agent/src/capture/dxgi.rs +++ b/agent/src/capture/dxgi.rs @@ -55,7 +55,7 @@ impl DxgiCapturer { /// Create D3D device and output duplication fn create_duplication( - display: &Display, + target_display: &Display, ) -> Result<(ID3D11Device, ID3D11DeviceContext, IDXGIOutputDuplication, DXGI_OUTDUPL_DESC)> { unsafe { // Create DXGI factory @@ -63,7 +63,7 @@ impl DxgiCapturer { .context("Failed to create DXGI factory")?; // Find the adapter and output for this display - let (adapter, output) = Self::find_adapter_output(&factory, display)?; + let (adapter, output) = Self::find_adapter_output(&factory, target_display)?; // Create D3D11 device let mut device: Option = None; @@ -100,7 +100,7 @@ impl DxgiCapturer { "Created DXGI duplication: {}x{}, display: {}", desc.ModeDesc.Width, desc.ModeDesc.Height, - &display.name + target_display.name ); Ok((device, context, duplication, desc)) diff --git a/agent/src/session/mod.rs b/agent/src/session/mod.rs index 64c1e24..2339bc2 100644 --- a/agent/src/session/mod.rs +++ b/agent/src/session/mod.rs @@ -59,8 +59,9 @@ impl SessionManager { /// Run the session main loop pub async fn run(&mut self) -> Result<()> { - let transport = self.transport.as_mut() - .ok_or_else(|| anyhow::anyhow!("Not connected"))?; + if self.transport.is_none() { + anyhow::bail!("Not connected"); + } self.state = SessionState::Active; @@ -91,7 +92,17 @@ impl SessionManager { // Main loop loop { // Check for incoming messages (non-blocking) - while let Some(msg) = transport.try_recv()? { + // Collect messages first, then release borrow before handling + let messages: Vec = { + let transport = self.transport.as_mut().unwrap(); + let mut msgs = Vec::new(); + while let Some(msg) = transport.try_recv()? { + msgs.push(msg); + } + msgs + }; + + for msg in messages { self.handle_message(&mut input, msg)?; } @@ -107,6 +118,7 @@ impl SessionManager { let msg = Message { payload: Some(message::Payload::VideoFrame(encoded.frame)), }; + let transport = self.transport.as_mut().unwrap(); transport.send(msg).await?; } }