TL;DR What is the proper way to get UE4 to link to the debug version of PhysX?
I am attempting to work with the PhysX source code. I just want to be able to place breakpoints and step through the code. Mostly to dig around and maybe tweak a few things. I stumbled upon the PhysX project files in:
UnrealEngine\Engine\Source\ThirdParty\PhysX\PhysX-3.3\Source\compiler\vc12win64
Then to debug the physics engine I can run UE4, open the PhysX project, and attach the debugger to UE4. However there was a problem when stepping through the code (line by line), the debugger jumps all over the place across several lines of code. This happens because the PhysX code has been mostly optimized away because UE4 is using the production build of PhysX.
So clearly the solution is to get UE4 to use the debug build of PhysX.
I found the PhysX dll files in:
UnrealEngine\Engine\Binaries\ThirdParty\PhysX\PhysX-3.3\Win64\VS2013
There is PhysX3DEBUG_x64.dll and PhysX3PROFILE_x64.dll. I confirmed that UE4 is using the profile build by deleting PhysX3PROFILE_x64.dll and checking if UE4 complains, which it does.
Then In the UE4 source I found that the PhysX dll is loaded in PhysXLibs.cpp:
#if UE_BUILD_DEBUG && !defined(NDEBUG) // Use !defined(NDEBUG) to check to see if we actually are linking with Debug third party libraries (bDebugBuildsActuallyUseDebugCRT)
PhysX3CommonHandle = LoadLibraryW(*(RootPhysXPath + "PhysX3CommonDEBUG_x64.dll"));
nvToolsExtHandle = LoadLibraryW(*(RootPhysXPath + "nvToolsExt64_1.dll"));
PhysX3Handle = LoadLibraryW(*(RootPhysXPath + "PhysX3DEBUG_x64.dll"));
#if WITH_PHYSICS_COOKING || WITH_RUNTIME_PHYSICS_COOKING
PhysX3CookingHandle = LoadLibraryW(*(RootPhysXPath + "PhysX3CookingDEBUG_x64.dll"));
#endif
...
#else //UE_BUILD_DEBUG
PhysX3CommonHandle = LoadLibraryW(*(RootPhysXPath + "PhysX3CommonPROFILE_x64.dll"));
nvToolsExtHandle = LoadLibraryW(*(RootPhysXPath + "nvToolsExt64_1.dll"));
PhysX3Handle = LoadLibraryW(*(RootPhysXPath + "PhysX3PROFILE_x64.dll"));
#if WITH_PHYSICS_COOKING || WITH_RUNTIME_PHYSICS_COOKING
PhysX3CookingHandle = LoadLibraryW(*(RootPhysXPath + "PhysX3CookingPROFILE_x64.dll"));
#endif
From that code I figure that I need to enable UE_BUILD_DEBUG and undefine NDEBUG.
I figured that changing the project configuration to “Debug” would do both these things. But it didn’t.
So instead I tried going into UE4’s ‘Configuration Properties/NMake/Preprocessor Definitions’ and forcibly changing the line: ‘UE_BUILD_DEVELOPMENT=1’ with ‘UE_BUILD_DEBUG=1’ and removed the line ‘NDEBUG=1’
Then I rebuilt UE4. Now, in order to confirm that I really am using PhysX3DEBUG_x64.dll instead of PhysX3PROFILE_x64.dll:
I deleted PhysX3PROFILE_x64.dll but the engine complained about not finding PhysX3PROFILE_x64.dll
Then I did the opposite and deleted PhysX3DEBUG_x64.dll but the engine did not complain about not finding PhysX3DEBUG_x64.dll
Question: So what is the proper way to get UE4 to link to the debug version of PhysX?
P.S. I’m using version 4.8 commit: 1933f7b14b1ff111916a3b0d0a7f45736654d3f9