MediaPipeUnityPlugin icon indicating copy to clipboard operation
MediaPipeUnityPlugin copied to clipboard

BoxTrackingGraph crashes on Windows

Open homuler opened this issue 2 years ago • 0 comments

Plugin Version or Commit ID

https://github.com/homuler/MediaPipeUnityPlugin/commit/738f3f7eccc391bac943e68bbc2178c97a5db124

Unity Version

2021.3.3f1

Your Host OS

Windows 10 Pro

Target Platform

Windows Standalone

Target Device

No response

[Windows Only] Visual Studio C++ and Windows SDK Version

Visual Studio C++: 14.16.27023 Windows SDK: 10.0.10240.0

[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 cpu --opencv cmake -vv

Bug Description

After running the BoxTrackingGraph, CalculatorGraph#WaitUntilDone is called. On Linux or macOS, it finishes successfully, but on Windows, UnityEditor crashes frequently.

Steps to Reproduce the Bug

I've not found a way to reproduce this error reliably, but in my environment, the following steps almost always cause errors.

  1. Play the Box Tracking scene.
  2. Run the scene for a while (about 5 secs)
  3. Stop the scene.

The 3rd step has a high probability of failure.

Log

I tested with the following patch applied.

diff --git a/Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs b/Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs
index 49dd3d1..54dde98 100644
--- a/Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs
+++ b/Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs
@@ -149,6 +149,7 @@ namespace Mediapipe.Unity
       {
         if (_isRunning)
         {
+          Logger.LogInfo(TAG, "Closing All Packet Sources");
           using (var status = calculatorGraph.CloseAllPacketSources())
           {
             if (!status.Ok())
@@ -157,6 +158,7 @@ namespace Mediapipe.Unity
             }
           }

+          Logger.LogInfo(TAG, "Waiting Until Done");
           using (var status = calculatorGraph.WaitUntilDone())
           {
             if (!status.Ok())
@@ -166,9 +168,12 @@ namespace Mediapipe.Unity
           }
         }

+        Logger.LogInfo(TAG, "Disposing CalculatorGraph");
+
         _isRunning = false;
         var _ = _NameTable.Remove(calculatorGraph.mpPtr);
         calculatorGraph.Dispose();
+        Logger.LogInfo(TAG, "Disposed CalculatorGraph");
         calculatorGraph = null;
       }

W20220520 14:18:19.695608 26756 motion_analysis_calculator.cc:351] No input video header found. Downstream calculators expecting video headers are likely to fail.
W20220520 14:18:19.730608 26760 motion_analysis_calculator.cc:744] Requested image format in RegionFlowComputation does not match video stream format. Overriding.
BoxTrackingGraph: Closing All Packet Sources
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,string,object)
Mediapipe.Unity.Logger/LoggerWrapper:Log (Mediapipe.Unity.Logger/LogLevel,string,object) (at Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Logger.cs:262)
Mediapipe.Unity.Logger:Log (Mediapipe.Unity.Logger/LogLevel,string,object) (at Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Logger.cs:138)
Mediapipe.Unity.Logger:LogInfo (string,object) (at Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Logger.cs:181)
Mediapipe.Unity.GraphRunner:Stop () (at Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs:152)
Mediapipe.Unity.BoxTracking.BoxTrackingGraph:Stop () (at Assets/MediaPipeUnity/Samples/Scenes/Box Tracking/BoxTrackingGraph.cs:37)
Mediapipe.Unity.GraphRunner:OnDestroy () (at Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs:104)

(Filename: Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs Line: 152)

BoxTrackingGraph: Waiting Until Done
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,string,object)
Mediapipe.Unity.Logger/LoggerWrapper:Log (Mediapipe.Unity.Logger/LogLevel,string,object) (at Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Logger.cs:262)
Mediapipe.Unity.Logger:Log (Mediapipe.Unity.Logger/LogLevel,string,object) (at Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Logger.cs:138)
Mediapipe.Unity.Logger:LogInfo (string,object) (at Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Logger.cs:181)
Mediapipe.Unity.GraphRunner:Stop () (at Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs:161)
Mediapipe.Unity.BoxTracking.BoxTrackingGraph:Stop () (at Assets/MediaPipeUnity/Samples/Scenes/Box Tracking/BoxTrackingGraph.cs:37)
Mediapipe.Unity.GraphRunner:OnDestroy () (at Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs:104)

(Filename: Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs Line: 161)

=================================================================
	Native Crash Reporting
=================================================================
Got a UNKNOWN while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
...

========== OUTPUTTING STACK TRACE ==================

0x00007FFE8B0314EE (VCRUNTIME140) memcpy
0x00007FFE02D98D8B (mediapipe_c) mp_SidePacket__size
0x00007FFE02D9690F (mediapipe_c) mp_SidePacket__size
0x00007FFE02D992B2 (mediapipe_c) mp_SidePacket__size
0x00007FFE02D98BA2 (mediapipe_c) mp_SidePacket__size
0x00007FFE03230273 (mediapipe_c) google::LogMessage::preserved_errno
0x00007FFE032282E2 (mediapipe_c) google::LogMessage::preserved_errno
0x00007FFE03228754 (mediapipe_c) google::LogMessage::preserved_errno
0x00007FFE0324D7A8 (mediapipe_c) google::LogMessage::preserved_errno
0x00007FFE0324DB91 (mediapipe_c) google::LogMessage::preserved_errno
0x00007FFE02F80D8F (mediapipe_c) mp_api__SetFreeHGlobal
0x00007FFE94CF6C0C (ucrtbase) recalloc
0x00007FFE94F354E0 (KERNEL32) BaseThreadInitThunk
0x00007FFE96F8485B (ntdll) RtlUserThreadStart

========== END OF STACKTRACE ===========

A crash has been intercepted by the crash handler. For call stack and other details, see the latest crash report generated in:
 * C:/Users/homul/AppData/Local/Temp/Unity/Editor/Crashes

And the stack trace.

000000e1`7ee2e7d8 00007ffd`fbb92052     : 0000024b`f7c8bdf0 00000000`00000000 00000000`00000000 00000000`00000000 : VCRUNTIME140D!memcpy+0x17c
000000e1`7ee2e7e0 00007ffd`fbb92602     : 0000024b`f0124550 000000e1`7ee2ea98 0000024c`1fcfdea0 0000024b`f70d9190 : mediapipe_c!mediapipe::TfLiteInferenceCalculator::ProcessInputsCpu+0x3e2
000000e1`7ee2e9c0 00007ffd`fbb948c5     : 000000e1`7ee2eea8 000000e1`7ee2f1b8 00000000`62872906 00007ffd`19772a4c : mediapipe_c!<lambda_80345c3f75ed76f59b4277e1e218a836>::operator()+0x1f2
000000e1`7ee2ecf0 00007ffd`fbb94305     : 000000e1`7ee2f1b8 000000e1`7ee2eea8 0000024b`638931d0 000000e1`7ee2ed88 : mediapipe_c!std::invoke<<lambda_80345c3f75ed76f59b4277e1e218a836> &>+0x25
000000e1`7ee2ed30 00007ffd`fbb92dac     : 000000e1`7ee2f1b8 000000e1`7ee2eea8 00000000`62872906 00007ffd`fbb935e3 : mediapipe_c!std::_Invoker_ret<absl::lts_20210324::Status,0>::_Call<<lambda_80345c3f75ed76f59b4277e1e218a836> &>+0x25
000000e1`7ee2ed70 00007ffd`fbb9521a     : 000000e1`7ee2eea0 000000e1`7ee2f1b8 000000e1`7ee2eea0 00007ffd`fbb94543 : mediapipe_c!std::_Func_impl_no_alloc<<lambda_80345c3f75ed76f59b4277e1e218a836>,absl::lts_20210324::Status>::_Do_call+0x2c
000000e1`7ee2edb0 00007ffd`fbb955e3     : 000000e1`7ee2eea0 000000e1`7ee2f1b8 000000e1`7ee2eea0 000000e1`7ee2ee80 : mediapipe_c!std::_Func_class<absl::lts_20210324::Status>::operator()+0x5a
000000e1`7ee2ee00 00007ffd`fbb90e94     : 0000024b`f0124550 000000e1`7ee2f1b8 000000e1`7ee2eea0 000000e1`7ee2f360 : mediapipe_c!mediapipe::TfLiteInferenceCalculator::RunInContextIfNeeded+0x33
000000e1`7ee2ee40 00007ffd`fd855ed7     : 0000024b`f0124550 000000e1`7ee2f1b8 0000024c`1fcfdea0 0000024a`ee8fab50 : mediapipe_c!mediapipe::TfLiteInferenceCalculator::Process+0x84
000000e1`7ee2ef00 00007ffd`fd853d60     : 0000024b`85b504a0 000000e1`7ee2f740 0000024c`1fcfdea0 00007ffd`fd969717 : mediapipe_c!mediapipe::CalculatorNode::ProcessNode+0xc27
000000e1`7ee2f710 00007ffd`fd852dfe     : 0000024b`632d6c30 0000024b`85b504a0 0000024c`1fcfdea0 000000e1`7ee2fae8 : mediapipe_c!mediapipe::internal::SchedulerQueue::RunCalculatorNode+0x520
000000e1`7ee2fa50 00007ffd`fd82bf0f     : 0000024b`632d6c30 00000000`0000000a 00000000`00000002 00000249`205a6998 : mediapipe_c!mediapipe::internal::SchedulerQueue::RunNextTask+0x31e
000000e1`7ee2fb80 00007ffd`fd823b03     : 000000e1`7ee2fcb8 000000e1`7ee2fc28 00000000`00000002 00000000`00000003 : mediapipe_c!<lambda_075d41e8035f165b89a0cf2ceecc99a8>::operator()+0x1f
000000e1`7ee2fbb0 00007ffd`fd819ba3     : 000000e1`7ee2fcb8 000000e1`7ee2fc28 00000000`00000002 00007ffd`fb8a6cd3 : mediapipe_c!std::invoke<<lambda_075d41e8035f165b89a0cf2ceecc99a8> &>+0x13
000000e1`7ee2fbe0 00007ffd`fd83011a     : 000000e1`7ee2fcb8 0000024b`37fb1450 000000e1`00000000 00000000`0000000a : mediapipe_c!std::_Invoker_ret<void,1>::_Call<<lambda_075d41e8035f165b89a0cf2ceecc99a8> &>+0x13
000000e1`7ee2fc10 00007ffd`fc6c269e     : 000000e1`7ee2fcb0 00000249`205a6998 00000000`00000000 0000024b`63a959b0 : mediapipe_c!std::_Func_impl_no_alloc<<lambda_075d41e8035f165b89a0cf2ceecc99a8>,void>::_Do_call+0x1a
000000e1`7ee2fc40 00007ffd`fd8b8751     : 000000e1`7ee2fcb0 0000024b`37fb1450 000000e1`7ee2fd68 00007ffd`fb9404c3 : mediapipe_c!std::_Func_class<void>::operator()+0x3e
000000e1`7ee2fc80 00007ffd`fd8b8ae7     : 00000249`205a6948 00000249`205a69e8 00000000`00000000 00007ffd`fb608ed3 : mediapipe_c!mediapipe::ThreadPool::RunWorker+0xb1
000000e1`7ee2fd10 00007ffd`fd8b9b57     : 0000024b`3dbde830 00007ffd`fb607138 000000e1`7ee2fdd8 00007ffd`fb609b64 : mediapipe_c!mediapipe::ThreadPool::WorkerThread::ThreadBody+0xc7
000000e1`7ee2fd90 00007ffd`fd8b9794     : 0000024b`f02dcaf8 0000024b`f02dcaf0 00000001`00000000 00007ffd`fb6072e9 : mediapipe_c!std::invoke<void * (__cdecl*)(void *),mediapipe::ThreadPool::WorkerThread *>+0x27
000000e1`7ee2fdd0 00007ffd`fb624c7c     : 0000024b`f02dcaf0 00000000`00000000 00000000`00000000 00000000`00000000 : mediapipe_c!std::thread::_Invoke<std::tuple<void * (__cdecl*)(void *),mediapipe::ThreadPool::WorkerThread *>,0,1>+0x64
000000e1`7ee2fe30 00007ffe`94f354e0     : 0000024b`3dbcf670 00000000`00000000 00000000`00000000 00000000`00000000 : ucrtbased!thread_start<unsigned int (__cdecl*)(void *),1>+0x9c
000000e1`7ee2fe90 00007ffe`96f8485b     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : kernel32!BaseThreadInitThunk+0x10
000000e1`7ee2fec0 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x2b

Screenshot/Video

No response

Additional Context

This error appears to be similar to a bug identified in earlier versions. In earlier versions, UnityEditor crashed only on Windows when the BoxTrackingGraph was run.

homuler avatar May 20 '22 05:05 homuler