homuler / MediaPipeUnityPlugin

Unity plugin to run MediaPipe
MIT License
1.76k stars 460 forks source link

Crashing when playing on windows unity editor. #118

Closed elblogbruno closed 3 years ago

elblogbruno commented 3 years ago

System information

Describe the current behavior I have implemented the hand graph, and when playing on the editor, sometimes at first play it does not crash but does not read data from the graph. When I play again, the editor crashes. Other times it crashes on the first try!

void OnEnable() {
    if (Application.isEditor)
    {
        useGPU = false;
    }
    var nameForGlog = Path.Combine(Application.dataPath, "MediaPipePlugin");
    var logDir = Path.Combine(Application.persistentDataPath, "Logs", "MediaPipe");
    print(logDir);
    print(nameForGlog);
    if (!Directory.Exists(logDir)) {
      Directory.CreateDirectory(logDir);
    }

    Glog.Initialize(nameForGlog, logDir);
    // for debugging
    System.Environment.SetEnvironmentVariable("GLOG_v", "5");
  }

I do have logging enable even though it does not create any log file and editor.log does not give any issue.

image I do have these files on the plugin folder, and the library to load on startup.

image

What could it be? Thanks for all! Describe the expected behavior

Steps to reproduce the issue Describe the exact steps to reproduce the issue. If you have changed or written code, please provide minimum code.

Full logs Please attach Editor.log (if it occurs on Unity Editor) or Player.log (if it occurs at runtime). See https://docs.unity3d.com/Manual/LogFiles.html

Additional context Add any other context about the problem here.

homuler commented 3 years ago

I have implemented the hand graph,

I guess this is essential. Can you provide minimum code to reproduce the issue? I'd like you to provide sufficient information to reproduce the issue on my machine.

In addition to that, will you provide the exact build command (e.g. python build.py build --desktop cpu -v) ?

By the way, I think this is unrelated to the issue, but below code contains subtle bug.

void OnEnable() {
   Glog.Initialize(nameForGlog, logDir);
   // for debugging
   System.Environment.SetEnvironmentVariable("GLOG_v", "5");
}

Environment variables need to be set before loading native libraries, but if you call Glog.Initialize, they will be loaded and GLOG_v won't take effect. However, on Windows, libmediapipe_c.dll will be loaded on startup, so swapping the lines does not solve the problem.

To set environment variables correctly, you need to set them first and start UnityEditor. Please see also https://support.unity.com/hc/en-us/articles/360044824951-I-need-to-start-Unity-with-an-environment-variable-s-set-how-can-I-do-that-

elblogbruno commented 3 years ago

Sorry for the late response, bit busy this week.

I have implemented the hand graph,

I guess this is essential. Can you provide minimum code to reproduce the issue? I'd like you to provide sufficient information to reproduce the issue on my machine.

I share them on Pastebin as it is a long code and this response will be too long. https://pastebin.com/0mDrUbQZ Here is my HandTrackingGraph.cs https://pastebin.com/EVjF2d1e Here is my DemoGraph.cs https://pastebin.com/UzPty9S5 And here CPUImageAcess a custom code that on the mobile phone gets images from CPU thanks to arfoundation and if on editor it tries getting images from webcam and pushing them to DemoGraph.

In addition to that, will you provide the exact build command (e.g. python build.py build --desktop cpu -v) ?

INFO (build.py): Building protobuf sources...
DEBUG (build.py): Running `bazel build -c opt //mediapipe_api:mediapipe_proto_srcs`
DEBUG: /home/bruno/.cache/bazel/_bazel_bruno/b0883a8cebe2ae5935cd4226823fc937/external/rules_foreign_cc/workspace_definitions.bzl:6:6: `@rules_foreign_cc//:workspace_definitions.bzl` has been replaced by `@rules_foreign_cc//foreign_cc:repositories.bzl`. Please use the updated source location
INFO: Analyzed target //mediapipe_api:mediapipe_proto_srcs (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //mediapipe_api:mediapipe_proto_srcs up-to-date:
bazel-bin/mediapipe_api/mediapipe_proto_srcs.zip
INFO: Elapsed time: 0.566s, Critical Path: 0.03s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
DEBUG (build.py): Unarchiving 'bazel-bin/mediapipe_api/mediapipe_proto_srcs.zip' to 'build/Scripts/Protobuf'...
INFO (build.py): Built protobuf sources
INFO (build.py): Downloading protobuf dlls...
DEBUG (build.py): Running `nuget install -o .nuget`
ADVERTENCIA: ''Google.Protobuf' already has a dependency defined for 'System.Memory'.'
Installing 'Google.Protobuf 3.15.6'.
'Google.Protobuf' already has a dependency defined for 'System.Memory'.
Traceback (most recent call last):
File "/home/bruno/MediaPipeUnity/MediaPipeUnityPlugin/build.py", line 357, in <module>
Argument().command().run()
File "/home/bruno/MediaPipeUnity/MediaPipeUnityPlugin/build.py", line 104, in run
self._run_command(self._build_proto_dlls_commands())
File "/home/bruno/MediaPipeUnity/MediaPipeUnityPlugin/build.py", line 43, in _run_command
return subprocess.run(command_list, check=True)
File "/home/bruno/.pyenv/versions/3.9.0/lib/python3.9/subprocess.py", line 524, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['nuget', 'install', '-o', '.nuget']' returned non-zero exit status 1.

I have set the environment variables correctly now, still get no logging. Cordially, Bruno

homuler commented 3 years ago

It looks like build.py failed. Which version of NuGet do you use?

elblogbruno commented 3 years ago

image Can't seem to get the current version of NuGet.

elblogbruno commented 3 years ago

Update: Ok fixed the issue above on the image. Had to install mono on my Debian machine. But still, have the error at the other response!

ADVERTENCIA: ''Google.Protobuf' already has a dependency defined for 'System.Memory'.'
Installing 'Google.Protobuf 3.15.6'.
'Google.Protobuf' already has a dependency defined for 'System.Memory'.
Traceback (most recent call last):
  File "/home/bruno/MediaPipeUnity/MediaPipeUnityPlugin/build.py", line 362, in <module>
    Argument().command().run()
  File "/home/bruno/MediaPipeUnity/MediaPipeUnityPlugin/build.py", line 109, in run
    self._run_command(self._build_proto_dlls_commands())
  File "/home/bruno/MediaPipeUnity/MediaPipeUnityPlugin/build.py", line 47, in _run_command
    return subprocess.run(command_list, check=True)
  File "/home/bruno/.pyenv/versions/3.9.0/lib/python3.9/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['nuget', 'install', '-o', '.nuget']' returned non-zero exit status 1.
elblogbruno commented 3 years ago

It looks like build.py failed. Which version of NuGet do you use? NuGet Version: 5.8.1.7021

homuler commented 3 years ago

As to above errors, will you remove .nuget directory and try again?

By the way, I guess you're running UnityEditor on Windows. If so, you need to build them on Windows, not Debian, so please run the build command on Windows.

elblogbruno commented 3 years ago

Oopsie Doopsie I was building on Debian for windows 🤦‍♂️ But I will look as weel to the issue so I can build for Linux as well.

elblogbruno commented 3 years ago

I successfully build in windows the mediapipe dll for windows desktop and still having the same issues. Maybe it can be code-related, I will investigate furthermore.

homuler commented 3 years ago

https://github.com/homuler/MediaPipeUnityPlugin/commit/e00e4ae8d35af780e5ff8fa38b09efbea433b473 fixed the problem described in https://github.com/homuler/MediaPipeUnityPlugin/issues/118#issuecomment-817185599

elblogbruno commented 3 years ago

Thanks! Still haven't found out time to investigate the main issue furthermore sorry if I still keep the issue open!

elblogbruno commented 3 years ago

Hello @homuler ! Still crashing. Maybe it is related with this issue that pops up when Unity Loads?

Plugins: Failed to load '{project path}/Packages/com.github.homuler.mediapipe/Runtime/Plugins/libmediapipe_c.dll' because one or more of its dependencies could not be loaded.

Maybe I am building the dll bindings in a not correct way or is something related to my computer. Will try on my laptop and see if it crashes.

elblogbruno commented 3 years ago

Seem to fix it finally! It was related somehow with the way of how the SceneDirector.cs code and my webcam accessing code was structure that made that crash. I did try on the same project with your code and it did not crash, so that lead me to take a look at that.

Thanks for all Cordially, Bruno