homuler / MediaPipeUnityPlugin

Unity plugin to run MediaPipe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using GetPixel32() in video motion capture cause gc alloc,finally lead to intermittent lag.

K4N114 opened this issue · comments

Plugin Version or Commit ID

v0.14.3

Unity Version

2022.3.10f1

Your Host OS

Windows11

Target Platform

UnityEditor

Target Device

PC

[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

~

Bug Description

When running the sample 'Pose Tracking Scene' with a video input in Unity editor,I found the constantly lagging of ‘game’ window.
So I checked the profiler and found that it's
'TextureFrame.cs'->'ReadTextureFromOnCPU()'->'GetPixel32()'
cause continuous 0.8MB gc alloc each frame.
So I tried this.

public void ReadTextureFromOnCPU(Texture src)
{
  //Original
  //var textureBuffer = LoadToTextureBuffer(src);
  //SetPixels32(textureBuffer.GetPixels32());
  
  //Mine
  var textureBuffer = LoadToTextureBuffer(src);
  textureBuffer.GetRawTextureData<byte>().CopyTo(_texture.GetRawTextureData<byte>());
  _texture.Apply();
}

Which solved the problem.

Steps to Reproduce the Bug

1.Select the 'AppSetting' prefab,switch the 'Default Image Source' to 'Video' then add a video clip below.
2.Open the 'Pose Tracking' template scene.
3.Run in editor.

Log

~

Screenshot/Video

No response

Additional Context

No response