C++ Plugin can't delay load a dll

1

I am bridging Nvidia Blast to Unity, and I am running into the following error when PhysX is trying to delay load PhysX3CommonDEBUG_x64.dll:

Unhandled exception at 0x00007FFDD7743FB8 (KernelBase.dll) in Unity.exe: 
0xC06D007E: Module not found (parameters: 0x00000000005FC5B0).`

I am able to run this bridging program fine as a standalone console application (after changing the project type), but running the PhysX initialization inside of Unity causes the crash (here's Unity's stacktrace):

0x00007FFF4F543FB8 (KERNELBASE) RaiseException
0x00007FFEF0840835 (PhysX3DEBUG_x64) [f:\dd\vctools\delayimp\delayhlp.cpp:323] __delayLoadHelper2 
0x00007FFEF0669011 (PhysX3DEBUG_x64) _tailMerge_physx3commondebug_x64_dll
0x00007FFEF051CDA4 (PhysX3DEBUG_x64) [c:\users\jesse\documents\github\physx-3.4\physx_3.4\source\physx\src\npfactory.cpp:67] physx::NpFactory::NpFactory
0x00007FFEF051D6ED (PhysX3DEBUG_x64) [c:\users\jesse\documents\github\physx-3.4\physx_3.4\source\physx\src\npfactory.cpp:122] physx::NpFactory::createInstance
0x00007FFEF0545721 (PhysX3DEBUG_x64) [c:\users\jesse\documents\github\physx-3.4\physx_3.4\source\physx\src\npphysics.cpp:269] physx::NpPhysics::createInstance
0x00007FFEF0544DAA (PhysX3DEBUG_x64) [c:\users\jesse\documents\github\physx-3.4\physx_3.4\source\physx\src\npphysics.cpp:831] PxCreateBasePhysics
0x00007FFF18D37FA3 (Fractre) [c:\users\jesse\documents\github\blast\compiler\fractre\fractre.cpp:60] Initialize 

I can definetely confirm that PhysX3CommonDEBUG_x64.dll and all other dlls are present in plugin directory (like Unity expects) and there were complaints when they were missing but now they've been addressed.

I have also ran Window's System File Checker and it found no integrity issues.

c++
unity3d
visual-c++
asked on Stack Overflow Feb 14, 2018 by AquaGeneral • edited Jun 20, 2020 by Community

2 Answers

0

confirm that PhysX3CommonDEBUG_x64.dll and all other dlls are present in plugin directory (like Unity expects)

It doesn’t matter what Unity expects. When you use /DELAYLOAD linker flag to link with a native DLL, it’s not Unity who’s loading that DLL — Windows does.

Here’s a documentation about DLL search order. There’s a special API you can call to specify custom DLL location but handle with care, could be security consequences if someone will trick your app to load a hacked version of that DLL instead of the correct one.

Couple other notes. Ensure you’re using correct architecture, i.e. both Unity project and PhysX are 64 bit. Also ensure any DLLs PhysX3CommonDEBUG depends on are also available for LoadLibrary.

answered on Stack Overflow Feb 17, 2018 by Soonts
0

Here's 3 solutions that will work (as of PhysX 4.1):

  • Build PhysX statically
  • Remove the DELAYLOAD/ from their CMake.
  • Load the libraries that need to be delay loaded yourself. Just import kernel32 LoadLibrary (or dlopen/close on unix) and call it on those few libraries before calling any functions that would have had it loaded.
answered on Stack Overflow Mar 23, 2020 by Andrew Wilson

User contributions licensed under CC BY-SA 3.0