-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.31.0 C# Wrapper Crash #5369
Comments
Sorry for the delay, looking into it |
Thanks for reporting, the crash is a bug and shouldn't happen... The problem is the internal handle is copied from the original sensor to the pose sensor. Once a sensor is disposed, the native handle is no longer valid, and the second sensor now points to an invalid handle, so a There are several possible fixes:
Note that |
Thanks for the options @ogoshen Here's a try at number 1: cs_wrapper_fix Let me know if it looks ok to you and I can make a pull request. Thanks. |
Looks good, Though the more I think about it, seems like 3 + manual ref counting is the proper way to go. The ref counter can either be a field in relevant types, or maybe better (but requires .NET>=4) use a |
…eleterHandler and use DeleterHandler references when creating new managed objects with the same underlying native objects
Great job! Do have a couple of notes worth discussing:
|
Thanks @ogoshen , my responses to your notes below.
The updates are in this commit Let me know if this looks ok to you. Thanks again. |
Looks great! Just one small issue here with: //Reset the instance ref to an invalid handle
m_instance = new RefCountedDeleterHandle(); I'd like to avoid this allocation, the empty invalid handle could be a singleton (might also convey the meaning better), something like this should work: public static readonly RefCountedDeleterHandle Empty;
static RefCountedDeleterHandle()
{
Empty = new RefCountedDeleterHandle(IntPtr.Zero, null);
GC.SuppressFinalize(Empty);
} I'm still not 100% happy about everything looking like it's ref counted, and would have liked an extra field where needed with something like a RefCountDisposable wrapping the But your design certainly has advantages, the biggest is the simplicity for adding new types. You've got my 👍 for a PR |
Hi @ogoshen I realized I should test the changes more thoroughly before doing a PR and when doing so This was a fatal flaw in my design and highlights that doing managed ref-counting for all objects is unnecessary and can only cause problems. So I started over and attempted to implement what you described and adapted The re-done changes are here Thanks for iterating on this with me, and apologies if I made this more difficult than it needed to be. Happy new year! Edit: I'll also include this commit in the PR to return ref-counted objects to its pool on Edit: I also included this commit in the PR since I realized the refcount needed to be pulled from a table indexed by the Handle |
Great that you caught it in time! My suggestion was only intuitive, I'm glad to see it had merit. So great that there was already a thread safe implementation for reference, getting those things right is hard.. might not have been necessary here, but better safe than sorry.
No problem, and you haven't. |
Issue Description
I'm experiencing a crash when using the C# wrapper in the development branch (2.31.0). The following code causes a crash:
There appears to be one call to
NativeMethods.rs2_create_sensor
inSensorList
but two calls toNativeMethods.rs2_delete_sensor
each when thesensor
and theposeSensor
above are disposed.Previously
SensorList
was generic so I could callQuerySensors()
with thePoseSensor
type directly but this was changed in #5170How do I now get a PoseSensor from a device?
Thanks.
The text was updated successfully, but these errors were encountered: