[BUG] Unity crashes on macOS if HOME is not set

When trying to run a Unity build through the Terminal in our Jenkins build job, Unity is crashing with “Segmentation fault: 11”. This started happening when I tried to update our build process to use 2018.3.12f1, but it continued to happen after rolling back to 2018.3.3f1, which was previously working fine.

Details

Operating System: macOS Mojave (10.14.4)
Unity Version: 2018.3.12f1

I’ve reduced the command we use to launch unity to the following:

/Applications/Unity2018.3.12f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -nographics -logFile -noUpm

When run manually in the terminal, this successfully loads the project, attempts to compile (and fails because packages are disabled), and then quits. When run through Jenkins from a remote machine, however, it produces the following output:

14:23:53 + /Applications/Unity2018.3.12f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -nographics -logFile -noUpm
14:23:54 Initiating legacy licensing moduleDisplayProgressbar: Unity license
14:23:54
14:23:54 LICENSE SYSTEM [2019415 14:23:54] Next license update check is after 2019-04-16T14:33:17
14:23:54
14:23:54 /var/folders/nw/xf229xdj1mb9bjg8xgp19lqh0000gn/T/jenkins2051546300913103158.sh: line 2:   579 Segmentation fault: 11  /Applications/Unity2018.3.12f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -nographics -logFile -noUpm

It appears that Unity is crashing with a segmentation fault before it’s even able to get started.

If I remove the “-noUpm” flag, I get the following additional error coming from the package manager:

14:39:27 + /Applications/Unity2018.3.12f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -nographics -logFile
14:39:27 Initiating legacy licensing moduleDisplayProgressbar: Unity license
14:39:27
14:39:27 LICENSE SYSTEM [2019415 14:39:27] Next license update check is after 2019-04-16T14:33:17
14:39:27
14:39:27 [Package Manager] Server::Start -- Port 63746 was selected
14:39:27 Launching external process: /Applications/Unity2018.3.12f1/Unity.app/Contents/Resources/PackageManager/Server/UnityPackageManager
14:39:27 /var/folders/nw/xf229xdj1mb9bjg8xgp19lqh0000gn/T/jenkins274473516227971788.sh: line 2:   584 Segmentation fault: 11  /Applications/Unity2018.3.12f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -nographics -logFile
14:39:28 path.js:28
14:39:28     throw new TypeError('Path must be a string. Received ' + inspect(path));
14:39:28     ^
14:39:28
14:39:28 TypeError: Path must be a string. Received undefined
14:39:28     at assertPath (path.js:28:11)
14:39:28     at Object.join (path.js:1236:7)
14:39:28     at getLogFolder (/snapshot/upm/packages/server/diagnostics.js:0:0)
14:39:28     at enableDiagnostics (/snapshot/upm/packages/server/diagnostics.js:0:0)
14:39:28     at Object.<anonymous> (/snapshot/upm/packages/server/app.js:0:0)
14:39:28     at Module._compile (pkg/prelude/bootstrap.js:1252:22)
14:39:28     at Object.Module._extensions..js (module.js:661:10)
14:39:28     at Module.load (module.js:563:32)
14:39:28     at tryModuleLoad (module.js:503:12)
14:39:28     at Function.Module._load (module.js:495:3)
14:39:28     at Function.Module.runMain (pkg/prelude/bootstrap.js:1307:12)
14:39:28     at startup (bootstrap_node.js:227:16)
14:39:28     at bootstrap_node.js:648:3

While this issue appears to be related to how our build process is setup, it seems like there’s also a bug in Unity that’s causing it to crash, rather than provide a useful error message.

Additional Notes

  • Our builds were originally succeeding on 2018.3.3f1, so I assumed the issue was specific to 2018.3.12f1. However, even after going back to 2018.3.3f1 the builds now fail with the same error message.
  • Before each build, I clean the workspace and undo all modification, but leave the Library folder intact.
  • If I manually connect to the build machine, open a terminal, and run the exact same command that’s being run by Jenkins, Unity is able to launch successfully and produces the expected output. Something about the Jenkins build environment is causing Unity to crash.
  • Before running the first build that failed, I updated the operating system version to macOS 10.14.4 (I think it was previously on 10.14.3). Perhaps there’s something in the latest version of Mojave that’s causing Unity to crash?

Please let me know if there’s any other information I can provide. I appreciate any help anyone can offer!

Some updates as we continue to investigate this on our end:

  • We were able to confirm that builds work if manually connect over SSH (in addition to using Remote Desktop) and invoke Unity via the terminal.
  • Builds seem to be working if we use an otherwise identical machine that’s still on macOS 10.14.3, so it would appear that some change in the 10.14.4 update is causing Unity to crash.
  • We were able to fix some configuration issues in our Jenkins setup which got Unity’s crash handler working again, which gave us a crash dump. I’ve attached the crash dump to this post, but the most interesting chunk appears to be the following:
Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [4065]

VM Regions Near 0:
-->
    __TEXT                 0000000100000000-0000000104a19000 [ 74.1M] r-x/rwx SM=COW  /Applications/Unity2018.3.12f1/Unity.app/Contents/MacOS/Unity

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_platform.dylib          0x00007fff720b5712 _platform_strlen + 18
1   com.unity3d.UnityEditor5.x        0x0000000100184ca7 core::basic_string<char, core::StringStorageDefault<char> >::basic_string(char const*) + 71
2   com.unity3d.UnityEditor5.x        0x00000001006ec907 systeminfo::GetPersistentDataPath() + 55
3   com.unity3d.UnityEditor5.x        0x000000010121a17c GetBrowserPath() + 44
4   com.unity3d.UnityEditor5.x        0x0000000101216325 GetBrowserCachePath() + 37
5   com.unity3d.UnityEditor5.x        0x0000000101216078 CefInstance::IsBrowserCacheEmpty() + 40
6   com.unity3d.UnityEditor5.x        0x00000001019b8022 Application::InitializeProject() + 82
7   com.unity3d.UnityEditor5.x        0x0000000100727a6c NoGraphicsMain() + 60
8   com.unity3d.UnityEditor5.x        0x0000000100727dff EditorMain(int, char const**) + 831
9   com.unity3d.UnityEditor5.x        0x0000000100728289 main + 9
10  libdyld.dylib                     0x00007fff71ed33d5 start + 1

Looks like a null reference error when calling strlen when trying to get the persistent data path. Any idea what we could be doing wrong to cause this error?

4437271–405856–crash-dump.txt (59.3 KB)

After some more digging, we were able to determine that the issue was coming from the HOME environment variable not being set: Unity crashes with a segfault if it’s not set, but runs fine. We were also able to look back at the build jobs that had previously succeeded and were able to confirm that HOME was set for those jobs, but after updating to macOS 10.14.4 HOME was no longer set for the worker nodes. As such it’s worth noting:

  • The issue doesn’t appear to be specific to macOS 10.14.4, Unity will crash on any version if HOME isn’t set.
  • The issue isn’t specific to any recent version of Unity, since it was happening on both 2018.3.3f1 and 2018.3.12f1.
  • The issue is likely macOS-specific, as the docs for the persistent data path note that Unity specifically searches relative to the user’s home directory on macOS.

While this issue is effectively resolved for us (since we can manually set HOME to get our builds working again), Unity probably shouldn’t crash if the HOME variable isn’t set. It would have been much better for us (and would have saved us a ton of time) if it instead exited with an error code and printed a message clearly stating what went wrong.

1 Like

I’m so excited to find a relative answer all over the world, and I‘m sure that the problem I meet is exactly the same as your descriptions. However, I can not understand the resulotion you give which says I can manually set HOME to make it work.:frowning: Can you explain what the HOME environment refers to? About Jenkins or Unity or MacOS? How can I set it to get the build work correctly… Thank you veeeeeeeeeeery much:)

1 Like