Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In current code the vtable of StreamErrorHandler gets stored and accessed correctly - that's why simple structs with trait implementations that don't read
self
work well. However, somewhere inside the entrails ofscreencapturekit-sys
the original struct gets dropped (but surprisingly not its vtable! you can verify this by adding custom Drop impl and seeing it triggered, while the vtable still routeson_error
calls correctly). This leads to segfaults (because due to vtable being stored correctly, the code tries to access already freed data, which leads to bad data access and sometimes segfaults).I tried taking ownership of the Handler somewhere inside the safe part of the library, but that involved a lot of lifetime annotations. It's still something we might want to do, because currently once the Handler gets added - it will never be freed and it will live inside the global HashMap forever. And sadly even when I got it to work, the original struct did not get dropped, but the address to
self
inside theon_error
callback was still wrong - most likely some pointer arithmetic issue (maybe due to the fact thatdyn Trait
is actually a double pointer?).I added a simple test to showcase the source of the issue. Without my change the
error_rx.recv()
would return an Error claiming that error_tx has already been dropped. What's worse is thatself.error_tx.send(())
would result in segfaults.My next step might be actually passing the error given by SCK back to the handler (which currently takes no arguments).
Thanks for having a look.