Can't load PhysX modules if run from within a long path

There is a consistent issue with running a packaged game from within a “long” path on Windows. For example, if you make a packaged build of the ShooterGame using stock UnrealEngine 4.8.3, and run it from here:


D:\Temp\Longpath\01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\ShooterGame\Packaged\WindowsNoEditor\ShooterGame\Binaries\Win64\ShooterGame.exe

The game will crash on startup:



---------------------------
The UE4-ShooterGame Game has crashed and will close
---------------------------
Fatal error!


KERNELBASE.dll {0x000007fefdcab3dd} + 0 bytes
ShooterGame.exe {0x000000014252fa09} + 0 bytes
ShooterGame.exe {0x0000000142882639} + 0 bytes
ShooterGame.exe {0x0000000140941e6a} + 0 bytes
ShooterGame.exe {0x000000013f52e83a} + 0 bytes
ShooterGame.exe {0x000000013f52549a} + 0 bytes
ShooterGame.exe {0x000000013f525b1a} + 0 bytes
ShooterGame.exe {0x000000013f537089} + 0 bytes
ShooterGame.exe {0x000000014252e81d} + 0 bytes
kernel32.dll {0x00000000779f59cd} + 0 bytes
ntdll.dll {0x0000000077c2b891} + 0 bytes
ntdll.dll {0x0000000077c2b891} + 0 bytes

---------------------------
OK   
---------------------------


The callstack isn’t very helpful, but if you build your own binary, you can see that it’s happening here:



 	KernelBase.dll!RaiseException()	Unknown
>	MyProject.exe!__delayLoadHelper2(const ImgDelayDescr * pidd, __int64 (void) * * ppfnIATEntry) Line 315	C++
 	MyProject.exe!__tailMerge_PhysX3CommonPROFILE_x64_dll()	Unknown
 	MyProject.exe!InitGamePhys() Line 329	C++
 	MyProject.exe!FEngineLoop::PreInit(const wchar_t * CmdLine) Line 1259	C++
 	MyProject.exe!GuardedMain(const wchar_t * CmdLine, HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, int nCmdShow) Line 110	C++
 	MyProject.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) Line 189	C++
 	MyProject.exe!__tmainCRTStartup() Line 618	C
 	kernel32.dll!BaseThreadInitThunk()	Unknown
 	ntdll.dll!RtlUserThreadStart()	Unknown


It’s a “Module not found” exception, and the DLL that it’s trying to load is PhysX3CommonPROFILE_x64.dll. I haven’t gone deeper to investigate why exactly, but it looks like something fails in the delayed DLL loading procedure when the binary path is long enough.

Has anyone bumped into a similar issue or found a workaround? The “long path” isn’t very long, in my tests the game crashed when full binary path was 188 chars long, quite far even from the embarrassing 260 chars of MAX_PATH! Please share your findings :slight_smile: