MediaPipeUnityPlugin
MediaPipeUnityPlugin copied to clipboard
UI freezes when stopping / disposing mediapipe graph
Plugin Version or Commit ID
v0.10.1
Unity Version
2021.3.3f1
Your Host OS
Windows 10 Pro
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 --android fat --android_ndk_api_level 21 --solutions pose -vv --opencv cmake -v --linkopt=-s
Bug Description
When the mediapipe graph is stopped this function gets called, it executes the following code:
public virtual void Stop()
{
if (calculatorGraph != null)
{
if (_isRunning)
{
using (var status = calculatorGraph.CloseAllPacketSources())
{
if (!status.Ok())
{
Logger.LogError(TAG, status.ToString());
}
}
using (var status = calculatorGraph.WaitUntilDone())
{
if (!status.Ok())
{
Logger.LogError(TAG, status.ToString());
}
}
}
_isRunning = false;
var _ = _NameTable.Remove(calculatorGraph.mpPtr);
calculatorGraph.Dispose();
calculatorGraph = null;
}
if (_stopwatch != null && _stopwatch.IsRunning)
{
_stopwatch.Stop();
}
}
However when this code sometimes fails without an error message, also Unity is still reactive but the UI is frozen. You can still hear the app reacting to button clicks but the UI never updates.
changing the above code to
public virtual void Stop()
{
if (calculatorGraph != null)
{
if (_isRunning)
{
using (var status = calculatorGraph.CloseAllPacketSources())
{
if (!status.Ok())
{
Logger.LogError(TAG, status.ToString());
}
}
}
_isRunning = false;
var _ = _NameTable.Remove(calculatorGraph.mpPtr);
calculatorGraph = null;
}
seems to fix the problem, but it's unclear where the error comes from in the first place.
Does anyone have a clue where this problem might come from?
Steps to Reproduce the Bug
Some more context:
This bug occurs from time to time but is very hard to reproduce. In some builds it never occurs. But it seems that we can trigger it on some devices reliably by calling the above mentioned Stop () function manually.
Before hunting the bug it occured on Unity Scene changes (which also involves calling the Stop () function on the GraphRunner).
Log
There is no Log message. Unity keeps on running fine in the background an is responsive, only UI is frozen
Screenshot/Video
No response
Additional Context
No response
There is no Log message.
Are there still no log messages if you build the app with Development Build enabled?
In addition to that, you need to change the value of Glog.V (e.g. Glog.V = 5;) to examine the internal of MediaPipe.
But it seems that we can trigger it on some devices reliably by calling the above mentioned Stop () function manually.
On which device are you testing?
In some apk builds the bug occured every time / reliably (e.g. on Samsung Galaxy Tab S7 or Huawei P30). Sometimes rebuilding the exact same project using a different computer caused the bug to disappear.
yes, developement build was enabled. I will go and try the Glog.V = 5 option. Thx for the hint. Will follow up on this...