sentis-samples icon indicating copy to clipboard operation
sentis-samples copied to clipboard

Bug: Null Reference in Unity Inference Engine code

Open crawfis opened this issue 6 months ago • 2 comments

I get a null reference deep in the bowels of the code sporadically when I try to use this in a stress test. Error is below. I tested with both BackendType.CPU and BackendType.GPUCompute for the Workers. Seems to be an issue with: ./Library/PackageCache/com.unity.ai.inference@89644c5bfb09/Runtime/Core/TensorGeneric.cs:157

Sample that tests a sequence of images, videos and webcam by cycling through these is here: Dr. Crawfis' BlazePose Refactor for Unity

----------------Null Reference-------------- NullReferenceException: Object reference not set to an instance of an object UnityEngine.Awaitable1[T].SetResultAndRaiseContinuation (T result) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable+AwaitableAsyncMethodBuilder1[T].SetResult (T value) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) Unity.InferenceEngine.Tensor1[T].ReadbackAndCloneAsync () (at ./Library/PackageCache/com.unity.ai.inference@89644c5bfb09/Runtime/Core/TensorGeneric.cs:157) UnityEngine.Awaitable+AwaitableAsyncMethodBuilder1+StateMachineBox1[T,TStateMachine].DoMoveNext () (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable.RunOrScheduleContinuation (UnityEngine.Awaitable+AwaiterCompletionThreadAffinity awaiterCompletionThreadAffinity, System.Action continuation) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable.RaiseManagedCompletion () (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable1[T].SetResultAndRaiseContinuation (T result) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable+AwaitableAsyncMethodBuilder1[T].SetResult (T value) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) Unity.InferenceEngine.Tensor.ReadbackAndCloneAsync () (at ./Library/PackageCache/com.unity.ai.inference@89644c5bfb09/Runtime/Core/Tensor.cs:187) UnityEngine.Awaitable+AwaitableAsyncMethodBuilder1+StateMachineBox1[T,TStateMachine].DoMoveNext () (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable.RunOrScheduleContinuation (UnityEngine.Awaitable+AwaiterCompletionThreadAffinity awaiterCompletionThreadAffinity, System.Action continuation) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable.RaiseManagedCompletion () (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable1[T].SetResultAndRaiseContinuation (T result) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable+AwaitableAsyncMethodBuilder1[T].SetResult (T value) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) Unity.InferenceEngine.ComputeTensorData.DownloadAsync[T] (System.Int32 dstCount) (at ./Library/PackageCache/com.unity.ai.inference@89644c5bfb09/Runtime/Core/Backends/GPUCompute/ComputeTensorData.cs:144) UnityEngine.Awaitable+AwaitableAsyncMethodBuilder1+StateMachineBox1[T,TStateMachine].DoMoveNext () (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable.RunOrScheduleContinuation (UnityEngine.Awaitable+AwaiterCompletionThreadAffinity awaiterCompletionThreadAffinity, System.Action continuation) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable.RaiseManagedCompletion () (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Awaitable1[T].SetResultAndRaiseContinuation (T result) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0) UnityEngine.Rendering.AsyncGPUReadbackRequest.InvokeCallback (System.Action`1[T] callback, UnityEngine.Rendering.AsyncGPUReadbackRequest obj) (at <7fa9e22a6c4a40e5abbae8599fd0bce3>:0)

crawfis avatar Jun 22 '25 21:06 crawfis

I added a try/catch the main RunDetectionLoop outside of the While loop. I get 2 errors. One in the bowels of your code. I think you aren't cleaning up your compute shader or something.

Image

The other seems to be associated with this line, but is the same code that it runs sometimes great, other times with one of these 2 errors: var landmarksAwaitable = (m_PoseLandmarkerWorker.PeekOutput("Identity") as Tensor).ReadbackAndCloneAsync();

Image

crawfis avatar Jun 25 '25 11:06 crawfis

I fixed this by not create a new detector every time the image source changed. My github is updated. Good stress test though. I still get an error on the initial set-up but things seem to work fine with the webcam, videos and images. Would be good to have advice on how often the person detection should run. Now it runs every frame.

crawfis avatar Jun 28 '25 09:06 crawfis