-
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
App crashes when using Sensor.Start(FrameCallback) #1250
Comments
Hi @baSSiLL |
Thanks @dorodnic However, this API still appears of not much use to me because I need an instance of VideoFrame type to be used later in processing blocks. And AFAIK there is no way currently to convert from Frame to VideoFrame or any other specific frame type.
void Start(Action<TFrame> callback) where TFrame : Frame;
I'd vote for the 3d option. Let me know of your thoughts on this. |
[Realsense Customer Engineering Team Comment] would like to know the new tool "convert" can fit your need? |
Sorry for a late reply :) |
handle invalid enum options
Hi
I'm using D415 on PC with .NET wrapper.
I prefer push model for consuming frames. The only API I've found for that is Sensor.Start method taking a callback delegate. However, after calling it the app crashes suddenly (after processing a few frames) and debug output contains message about invoking a garbage-collected delegate.
Digging into the code revealed that Sensor.Start actually creates another ad-hoc delegate which it then passes to unmanaged code. But because this ad-hoc delegate is not referenced by any managed object it becomes a subject for garbage collection after leaving the method body. So, after it is collected, calls from unmanaged code lead to error.
To mitigate this issue, a reference to delegate should be stored somewhere. Some options include:
A private field in Sensor class. Storing a single delegate instance should be sufficient because no more than a single callback can be activated simultaneously. Care should be taken here regarding thread-safety.
Make the Start method return some token (a "black-box" data structure) which holds a reference to the delegate. And require to pass this token in a subsequent invocation of Stop method. This should force a responsible user of the class to hold the token (effectively keeping the delegate alive) for a period when the callback can be actually called.
For the time being I've worked the issue around by making a replacement method for Sensor.Start in my code which calls unmanaged rs2_start and does proper work of storing a reference to a delegate passed.
The text was updated successfully, but these errors were encountered: