question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PoseTrackingGraph::Stop() tries to call methods on null objects

See original GitHub issue

Plugin 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:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MoneyWonderscommented, May 10, 2022

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(); }

0reactions
wonwooleecommented, May 12, 2022

I agree with the solution @MoneyWonders proposed, which is simple and elegant 😄 I applied it to my code and it addressed my issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

can we call any method on null object? - java
No. In Java, null is not an object. Share.
Read more >
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found