-
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
Stack empty exception #8334
Comments
Hi @cdrose If you have a multicam C# application and suspect that your object pool may be filling up, a RealSense user in a case in the links below who was trying to optimize their application's speed had similar concerns. https://support.intelrealsense.com/hc/en-us/community/posts/360049434593-Object-Pool-Size The link below is also a useful C# reference about disposal. It may be helpful to review the above links to see whether it provides useful insights for your own case and return here with any new questions that this research creates. I would also add that if you have created a single application that handles multiple cameras (in the style of the rs-multicam example program) then it is recommended to use poll_for_frames() instead of wait_for_frames() for reasons described in this link: |
Hi @MartyG-RealSense, thanks for the speedy reply. I had already read the first two issues you mention, and have now read the third also. #7201 does sound like a similar issue although it is not mentioned what exception was actually thrown when the ObjectPool is empty, I am only guessing that is what has happened at this point. If that is the case then "Keep - bypass SDK frame pool to have more frames in memory" sounds like it may be a solution. I will try and work out how Keep should be used (I see there are a few references in the github issues). #5369 seems unrelated unless I have missed something important in that thread. #2422 I understand the discussion here but it is not relevant for my application. I can see how WaitForFrames() would be messy to use if one required multiple frames to be available before processing could continue, but in my case the cameras are used independently so I am free to process individual frames as they arrive with no need to syncronise the multi-camera setup. So for me the main questions to answer are: |
I researched the Stack Empty Exception thoroughly and can find no other cases of it in librealsense. The link below is the best information that I could find about dealing with it, and suggests that it may be happening due to the multi-threading. https://stackoverflow.com/questions/14121799/stack-empty-exception There is no other information relating to use of Keep() with C# to answer your questions about it and so I do not feel that I can recommend it, simply because there is insufficient information to conclude whether it is appropriate for your C# project. I will say though that Keep() has the limitation that because the frames are stored in the computer's memory until the pipeline is closed and the frames processed, it is best suited for recording durations of up to 30 seconds. This is because the computer's memory capacity is consumed by the frames as the seconds pass. I do not know of C# scripting examples for Keep() though, only C++ and Python ones. A C++ example of using Keep(), in case you wish to consider accessing C++ from C#, is in the link below, |
The lack of other librealsense issues relating to the Stack Empty exception does imply that its something particular to my current project. A concurrency issue due to multi-threading would make sense, I will look into it further. If the Stack Empty exception is not actually related to reaching the capacity of the ObjectPool then Keep is not the solution so I will see if I can solve my issue without using it. It would seem odd though that the frames are stored in memory until the pipeline is closed, surely one can still Dispose() of frames which have been stored with Keep() once they are no longer required. |
OK I'm not sure I'm totally qualified to fix this, but looking in ObjectPool.cs some things look a bit suspicious. The The Stack Empty exception that I get comes from
Edit: |
Given that the exception has been occurring sporadically for you (as reported in the opening comment of this discussion), the best way forward may be to continue catching the exceptions as you are already doing. |
Or, perhaps we should fix it?! I have recompiled the C# wrapper with the following change. Will test and confirm if it works.
|
Okay, thanks very much for the possible PR contribution! |
Hi @cdrose Do you have an update that you can provide about your case, please? Thanks! |
@MartyG-RealSense sorry been busy with other things last week, have yet to fully test my changes. Should be back on it later this week. |
Thanks very much for the update! |
I have tested my patched version of the C# wrapper and have not observed anything unexpected. I have also not seen a StackEmpty exception since making the change. As far as I can tell this change has fixed the issue. |
Excellent news @cdrose - thanks! |
Case closed due to successful outcome achieved and no further comments received. |
I had the same problem, it was a multi camera (4 camera's), multi treaded projected (Each couple of 2 camera's has it's own Tread with a Syncer object), resulting in the ObjectPool crash with the following stacktrace: Exception Info: System.InvalidOperationException Recompiling the Intel.Realsense wrapper with the Get method as shown by @cdrose fixed it. |
Thanks so much @PorschefanRoel for sharing your confirmation of successful use of the @cdrose method on this discussion! |
I am working on a multi-camera multi-threaded application using the C# wrapper and I get sporadic 'Stack empty' exceptions from librealsense. Sometimes on
pipeline.WaitForFrames()
but more often ondepthFrame = fs.DepthFrame.DisposeWith(fs)
orcolorFrame = fs.ColorFrame.DisposeWith(fs)
lines. The exceptions seem to be non terminal in that I can catch them and skip that frame and the application continues to capture frames and perform as expected.I gather that the ObjectPool is related to how librealsense reuses memory to avoid garbage collection overhead. I also wonder if perhaps the way I am using the library is a bit unusual in that I am capturing frames, extracting several small regions of interest and then packing them back into Frames before running the depth filtering process. Benchmarking it shows a significant speed up over trying to process the full frame for my application but it probably means I am using more objects at any one time than the average realsense application. Could this be related?
The stack trace from Visual Studio looks like this:
The realsense logs aren't much help:
The text was updated successfully, but these errors were encountered: