scrap icon indicating copy to clipboard operation
scrap copied to clipboard

Capturer::new SIGSEGV on MacOS when called multiple times

Open framp opened this issue 5 years ago • 0 comments

use scrap::*;

fn main() {
  for i in 1..100 {
    let display = Display::primary()?;
    Capturer::new(display)?;
  }
}

Not that anyone would want to initialise the Capturer several times (I stumbled on this by accident) but I think this is caused by this:

After this call returns, the stream is stopped. When the stream stops, its callback is called
with a status of kCGDisplayStreamFrameStatusStopped. You must wait until this callback is 
received before releasing the display stream object.

https://github.com/quadrupleslap/scrap/blob/master/src/quartz/capturer.rs#L75

I tried keeping a pointer reference and moving

            CFRelease(self.stream);
            dispatch_release(self.queue);

in the handler but it still sigsegv

I guess we would need to wait for the handler to be over inside drop

framp avatar Dec 06 '20 13:12 framp