PoseTrackingGraph::Stop() tries to call methods on null objects
See original GitHub issuePlugin Version or Commit ID
v0.9.1
Unity Version
2020.3.32f1
Your Host OS
Ubuntu 20.04
Target Platform
Android
Target Device
No response
[Windows Only] Visual Studio C++ and Windows SDK Version
No response
[Linux Only] GCC/G++ and GLIBC Version
No response
[Android Only] Android Build Tools and NDK Version
No response
[iOS Only] XCode Version
No response
Build Command
python build.py build --desktop gpu --android arm64 --opencv cmake
Bug Description
When PoseTrackingGraph runs in Async mode, output stream object are not initialized and remain as null.
However PoseTrackingGraph Stop()
method always tries to call RemoveAllListeners()
method on them, and thus NullReferenceException is raised.
public override void Stop()
{
_poseDetectionStream.RemoveAllListeners();
_poseDetectionStream = null;
_poseLandmarksStream.RemoveAllListeners();
_poseLandmarksStream = null;
_poseWorldLandmarksStream.RemoveAllListeners();
_poseWorldLandmarksStream = null;
_segmentationMaskStream.RemoveAllListeners();
_segmentationMaskStream = null;
_roiFromLandmarksStream.RemoveAllListeners();
_roiFromLandmarksStream = null;
base.Stop();
}
Steps to Reproduce the Bug
Please see Bug Description.
Log
NullReferenceException: Object reference not set to an instance of an object Mediapipe.Unity.PoseTracking.PoseTrackingGraph.Stop () (at Assets/Scripts/PoseTrackingGraph.cs:117) Mediapipe.Unity.GraphRunner.OnDestroy () (at Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs:104)
Screenshot/Video
No response
Additional Context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Resolving "Cannot call method * of null" or "Cannot read ...
Resolution : Any typeErrors (where a property or method cannot be read or called because of a null object) will log both the...
Read more >How to Fix and Avoid NullPointerException in Java
The NullPointerException occurs due to a situation in application code where an uninitialized object is attempted to be accessed or modified.
Read more >Tired of Null Pointer Exceptions? Consider Using Java SE ...
The variable computer is of type Optional<Computer> , so it is perfectly correct to call the map method. However, getSoundcard() returns an object...
Read more >Null Pointer Exception In Java
NullPointerException is thrown when program attempts to use an object reference that has the null value. These can be: Invoking a method from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue happens because GraphRunner will call Stop() in it’s OnDestroy(), and ImageSourceSolution do the same thing in Stop(). If you like to stop MediaPipe before close app, you will meet this issue. I think the better way to avoid this problem is add null-check in GraphRunner.Stop(), just like: public override void Stop() { _palmDetectionsStream?.RemoveAllListeners(); _palmDetectionsStream = null; _handRectsFromPalmDetectionsStream?.RemoveAllListeners(); _handRectsFromPalmDetectionsStream = null; _handLandmarksStream?.RemoveAllListeners(); _handLandmarksStream = null; _handWorldLandmarksStream?.RemoveAllListeners(); _handWorldLandmarksStream = null; _handRectsFromLandmarksStream?.RemoveAllListeners(); _handRectsFromLandmarksStream = null; _handednessStream?.RemoveAllListeners(); _handednessStream = null; base.Stop(); }
I agree with the solution @MoneyWonders proposed, which is simple and elegant 😄 I applied it to my code and it addressed my issue.