x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to debug PhysX?

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

Product Version: UE 4.8 Preview
Tags:
more ▼

asked May 30 '15 at 12:15 AM in C++ Programming

avatar image

Mastodon
88 7 10 14

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first
more ▼

answered Sep 23 '15 at 10:46 PM

avatar image

Mastodon
88 7 10 14

avatar image Timoses Oct 02 '15 at 08:32 PM

@Mastodon : Unfortunately, the link is not working any longer.

Does anybody know how to debug PhysX?

avatar image Mastodon Oct 07 '15 at 05:40 PM

The link is working fine for me, I also checked if it worked on friend's machines and it works fine for them too. Without having an NVIDIA dev forum account.

But if it still doesn't work for you try visiting the NVIDIA Developer Forums: https://devtalk.nvidia.com/ then go to "Visual and Game Development" > "PhysX and Physics Modeling" then my thread is "Visual Studio debugger on the PhysX code running inside UE4" by "Distro16"

avatar image Syed Nov 13 '17 at 04:44 AM

Just in case, anyone still cannot access the link above.. here is the post which solves it:-

You can compile UE4 with all third party libs in debug. In BuildConfiguration.cs just set

bDebugBuildsActuallyUseDebugCRT = true;

and recompile.

You can also compile with just physx in debug by modifying GetPhysXLibraryMode in PhysXBuild.cs. You will then need to make sure that the dlls also load with debug versions. This is done in LoadPhysXModules in PhysXLibs.cpp. The code should automatically load the correct dlls but if you get a crash it is likely that it has loaded profile dlls instead of the debug ones. It is straightforward to change the code to fix this.

With these changes you should be able to run in Development Editor config and have physx running in debug.

Cheers,

Gordon

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question