UE 4.26.2 Editor crashes at launch when trying to start the Unreal Build Tool

I don’t know where to post this or even how to characterize it. It’s a bug report at heart but I have no suggestions on how it could be reproduced because it makes no sense to me. OS is Windows 11.

The editor crashes when launching, at what it claims is 96%. Specifically it tries to run <PATH>/UnrealBuildTool.exe -Mode=QueryTargets -Output="<PATH>/Engine/Intermediate/TargetInfo.json" only to be met with an access violation. Here is the relevant portion of the log. I’ll attach the whole log as well, but it’s not terribly helpful.

[2023.04.21-20.46.14:505][  0]Launching UnrealBuildTool... [E:/Program Files/Unreal Engine - CSS/Engine/Binaries/DotNET/UnrealBuildTool.exe -Mode=QueryTargets -Output="E:/Program Files/Unreal Engine - CSS/Engine/Intermediate/TargetInfo.json"]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: === Critical error: ===
[2023.04.21-20.46.20:695][  0]LogWindows: Error: 
[2023.04.21-20.46.20:695][  0]LogWindows: Error: Fatal error!
[2023.04.21-20.46.20:695][  0]LogWindows: Error: 
[2023.04.21-20.46.20:695][  0]LogWindows: Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION 0x000000909ff7aa38
[2023.04.21-20.46.20:695][  0]LogWindows: Error: 
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x000000909ff7aa38 UnknownFunction []
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff45432b7e ntdll.dll!UnknownFunction []
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff45430624 ntdll.dll!UnknownFunction []
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff42b1675b KERNELBASE.dll!UnknownFunction []
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff42b535d6 KERNELBASE.dll!UnknownFunction []
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff443564d4 KERNEL32.DLL!UnknownFunction []
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007ffe4bca5654 UE4Editor-Core.dll!FWindowsPlatformProcess::CreateProc() [C:\ar\_work\UnrealEngine\UnrealEngine\Engine\Source\Runtime\Core\Private\Windows\WindowsPlatformProcess.cpp:349]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff1edea314 UE4Editor-DesktopPlatform.dll!FDesktopPlatformBase::InvokeUnrealBuildToolAsync() [C:\ar\_work\UnrealEngine\UnrealEngine\Engine\Source\Developer\DesktopPlatform\Private\DesktopPlatformBase.cpp:749]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff1edea40a UE4Editor-DesktopPlatform.dll!FDesktopPlatformBase::InvokeUnrealBuildToolSync() [C:\ar\_work\UnrealEngine\UnrealEngine\Engine\Source\Developer\DesktopPlatform\Private\DesktopPlatformBase.cpp:670]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff1ede9d56 UE4Editor-DesktopPlatform.dll!FDesktopPlatformBase::GetTargetsForProject() [C:\ar\_work\UnrealEngine\UnrealEngine\Engine\Source\Developer\DesktopPlatform\Private\DesktopPlatformBase.cpp:899]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff1ede97cb UE4Editor-DesktopPlatform.dll!FDesktopPlatformBase::GetTargetsForCurrentProject() [C:\ar\_work\UnrealEngine\UnrealEngine\Engine\Source\Developer\DesktopPlatform\Private\DesktopPlatformBase.cpp:921]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007ffe46f385c9 UE4Editor-UnrealEd.dll!EditorInit() [C:\ar\_work\UnrealEngine\UnrealEngine\Engine\Source\Editor\UnrealEd\Private\UnrealEdGlobals.cpp:129]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007ff731db09aa UE4Editor.exe!GuardedMain() [C:\ar\_work\UnrealEngine\UnrealEngine\Engine\Source\Runtime\Launch\Private\Launch.cpp:149]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007ff731db0c0a UE4Editor.exe!GuardedMainWrapper() [C:\ar\_work\UnrealEngine\UnrealEngine\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:137]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007ff731dc4dbd UE4Editor.exe!WinMain() [C:\ar\_work\UnrealEngine\UnrealEngine\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:268]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007ff731dc7aca UE4Editor.exe!__scrt_common_main_seh() [d:\agent\_work\63\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff4435269d KERNEL32.DLL!UnknownFunction []
[2023.04.21-20.46.20:695][  0]LogWindows: Error: [Callstack] 0x00007fff453ea9f8 ntdll.dll!UnknownFunction []
[2023.04.21-20.46.20:695][  0]LogWindows: Error: 

I first had the error with the slightly modified engine used by the game Satisfactory. After repeatedly re-installing the engine in different places, rebooting, updating drivers, etc, I occasionally succeeded in starting the editor once, only for the error to reappear for the next launch. No crash report dialogue opened either. I also installed the official, unmodified version of 4.26.2 and it had the very same error, though the dialogue did appear. I didn’t send a report.

In debugging I noticed that the problem happens in operating system code, or sometimes in function _searchenv_s. I wrote a little C program to start the UnrealBuildTool with the same command line and met the same error. It happens before the process has been fully created, though a PID is apparently assigned and it appears in Task Manager.

I can’t even.

I have kind of worked around the problem with a custom build of the engine (which takes absolutely forever, by the way - can I use something other than CL.exe for building?). The hack I made is just awful and amounts to sticking fingers in ears and saying “lalala can’t hear you”. Namely, in the file Engine/Source/Runtime/Core/Private/Windows/WindowsPlatformProcess.cpp I replaced the function CreateProcess with a shim function that uses Windows’ weird structured exception handling to catch and ignore any fatal errors that occur when running CreateProcess. I even had it write a sarcastic message to the log. Top quality low effort work!

So in short I literally can’t begin to even.

I’m not sure how to include a file, so here’s the log on pastebin.
https://pastebin.com/raw/c27gifFV