Skip to content

[WASAPI] Stream::drop panics on device loss #1256

Description

@Jaxx497

Hello, I want to say thank you for all of the hard work that has gone into this project, it's allowed me to create some really cool things!

Summary

Physically unplugging headphones (or other devices) may result in a panic. The panic originates from an .unwrap() on a result inside the push_command body (from stream.rs), which receives E_HANDLE (0x800700, "The handle is invalid") because the stream's worker thread has already exited and closed the event handle.

Platform

cpal version: 0.18.1
Platform: Windows (WASAPI host)

Reproduction

  1. Start an output stream on a physical device (headphones/USB DAC).
  2. Physically unplug the device.
  3. From the thread that owns the Stream, drop it (e.g. to rebuild against the new default).
  4. Panic: called Result::unwrap() on an Err value: Error { code: HRESULT(0x80070006), message: "The handle is invalid." } at stream.rs:461.

Relevant code

// src/host/wasapi/stream.rs:458

fn push_command(&self, command: Command) -> Result<(), SendError<Command>> {
    self.commands.send(command)?;
    unsafe {
        Threading::SetEvent(self.pending_scheduled_event).unwrap();   // panic
    }
    Ok(())
}

(StreamTrait::play and pause reach the same .unwrap())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions