doom-fish / screencapturekit-rs

Safe rust wrapper around Apple's ScreenCaptureKit
Apache License 2.0
83 stars 24 forks source link

Attempted to construct an Id from a null pointer #51

Open louis030195 opened 3 months ago

louis030195 commented 3 months ago

After upgrading to mac 15.0 got this error:

thread '' panicked at /Users/matthewdi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc_id-0.1.1/src/id.rs:52:9:
Attempted to construct an Id from a null pointer
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
libc++abi: terminating due to uncaught foreign exception
zsh: abort ./target/release/screenpipe --debug

Does not happen on mac 14.5 (m3)

using: https://github.com/RustAudio/cpal/pull/894

we had to stop using screencapturekit-rs temporarily: https://github.com/louis030195/screen-pipe/commit/e3ef9195dbaa33a9aa2cb2f6cde9b4bd67020a80

sorry not lot of information, not sure where is the issue

happy to dig more in details / send a PR in upcoming days

1313 commented 3 months ago

Thanks for using this lib! I've been a bit in hibernation during summer but can have a look soon.

There is another take on macOS framework bindings which I think looks promising: https://github.com/yury/cidre check out the SC module.

Cheers Per

wangfu91 commented 3 months ago

Got the same error on macOS 15 beta. Here is the stack trace using the store_audio example:

thread '<unnamed>' panicked at /Users/fluffy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc_id-0.1.1/src/id.rs:52:9:
Attempted to construct an Id from a null pointer
stack backtrace:
   0: std::panicking::begin_panic
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panicking.rs:693:12
   1: objc_id::id::Id<T,O>::from_ptr
             at /Users/fluffy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc_id-0.1.1/src/id.rs:52:9
   2: screencapturekit_sys::cm_sample_buffer_ref::CMSampleBufferRef::get_frame_info
             at ./screencapturekit-sys/./src/cm_sample_buffer_ref.rs:25:13
   3: <store_audio::StoreAudioHandler as screencapturekit_sys::stream_output_handler::UnsafeSCStreamOutput>::did_output_sample_buffer
             at ./screencapturekit-sys/examples/store_audio.rs:66:33
   4: <screencapturekit_sys::stream_output_handler::UnsafeSCStreamOutputHandler as objc_foundation::object::INSObject>::class::{{closure}}::stream_output
             at ./screencapturekit-sys/./src/stream_output_handler.rs:53:21

I believe it is because the CMSampleBufferGetSampleAttachmentsArray API returns NULL, and the code didn't check for that: https://github.com/svtlabs/screencapturekit-rs/blob/9a6b9f346bd30de0d2f9a02af36d4cf6461f4f3b/screencapturekit-sys/src/cm_sample_buffer_ref.rs#L23

A simple, temporary workaround I found is to set the createIfNecessary Bool parameter of CMSampleBufferGetSampleAttachmentsArray to true.

-- let raw_attachments_array = CMSampleBufferGetSampleAttachmentsArray(self, 0);
++ let raw_attachments_array = CMSampleBufferGetSampleAttachmentsArray(self, 1);