-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: immediate lock-up when using go library in Unity 6 #70734
Comments
I'm sorry, I don't know what Unity is. But from your description, this seems like a problem with Unity, not a problem with Go. Have you raised this with the developers of Unity? |
Unity is a 3D game engine that is used abundantly.
Plugins written in plain C/C++ work just fine in the Unity Editor. When you add (c-)go in the mix Unity locks-up, hence our believe that this (c-)go related. In the meantime we have a couple more findings:
|
Just to set expectations, while the problem may be Go related, since we don't know anything about Unity it's unlikely that we'll be able to figure this out. |
Appreciated that. We are willing to contribute. Any pointer on where to start debugging this issue would be appreciated. To set the scene, the following minimal example (from the ZIP files attached to the first post) is causing the lock-up: package main
// #include <stdio.h>
// #include <stdlib.h>
import "C"
import (
"fmt"
)
//export HelloWorld
func HelloWorld() {
fmt.Println("Hello from Go!")
}
func main() {} Build:
C#: private const string PluginRelativePath = "TestPlugin";
[DllImport(PluginRelativePath, EntryPoint = "HelloWorld", CallingConvention = CallingConvention.Cdecl)]
private static extern void HelloWorld();
void Start() {
Debug.Log("Calling HelloWorld on plugin...");
HelloWorld();
Debug.Log("Successfully called HelloWorld on plugin...");
} Unity locks up when executing |
I'm sorry, I have no idea. From your description, it works with one version of Unity and fails with a different one. So something must have changed in Unity, but I have no idea what. |
We have reported this issue to Unity (issue 91704, I do not have a public link (yet?)). Our own investigation (by sprinkling log lines in the go source code) has shown that the go runtime is at least reaching go/src/runtime/cgo/gcc_darwin_arm64.c Line 129 in 05d8984
and we see a number of threads spinning up in go/src/runtime/cgo/gcc_darwin_arm64.c Line 27 in 05d8984
when the plugin is loaded by the unity editor. But when we call the exported function, it immediately hangs. At this point, I have no clue where to look next. Are there other spots where I can add some log lines to see what is going on? Any pointer is greatly appreciated. |
When a Go library is built with |
Go version
go1.21.1 darwin/arm64 (we have observed identical behaviour when using go 1.23.1 and 1.23.4)
Output of
go env
in your module/workspace:What did you do?
When running on Apple Silicon hardware:
Prerequisites:
2022.3.43f1
repro project: Unity2022ReproProject.zip. Do not open the project yet.6000.0.28f1
repro project: Unity6ReproProject.zip. Do not open the project yet.brew install dylibbundler
).dylib
on MacOS (using cgo). You can use the included magefile.build/TestPlugin.dylib
to the extracted Unity 2022 project inAssets/Plugins/TestPlugin.dylib
.build/TestPlugin.dylib
to the extracted Unity 6 project inAssets/Plugins/TestPlugin.dylib
.What did you see happen?
In Unity 2022
Unity 2022 (and also other versions like Unity 2021 and Unity 2023) is working as expected.
Open the Unity 2022 project, open the
Scenes/SampleScene
and click the Play button. Observe that the Unity Console shows:If you open
~/Library/Logging/Unity/Editor.log
it will show:In Unity 6
Unity 6 is immediately locking up (showing a beachball spinner) as soon as any go API is called.
Open the Unity 6 project, open the
Scenes/SampleScene
and click the Play button. Observe that the Unity Console shows:If you open
~/Library/Logging/Unity/Editor.log
it will show:What did you expect to see?
Unity 2022 and Unity 6 to behave the same. Instead, Unity 2022 is behaving as expected wheras Unity 6 immediately locks-up the Unity Editor.
The text was updated successfully, but these errors were encountered: