FConstraintInstance::DisableProjection() causes crash

Calling DisableProjection() on a UPhysicsConstraintComponent’s FConstraintInstance causes a crash with the following callstack:

[2016.09.26-19.24.11:711][  0]LogWindows:Error: === Critical error: ===
[2016.09.26-19.24.11:711][  0]LogWindows:Error: 
[2016.09.26-19.24.11:711][  0]LogWindows:Error: Fatal error!
[2016.09.26-19.24.11:711][  0]LogWindows:Error: 
[2016.09.26-19.24.11:711][  0]LogWindows:Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000
[2016.09.26-19.24.11:711][  0]LogWindows:Error: 
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor-Engine.dll!FConstraintInstance::DisableProjection() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\engine\private\physicsengine\constraintinstance.cpp:1235]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor-VRArena.dll
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor-CoreUObject.dll!UClass::CreateDefaultObject() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\coreuobject\private\uobject\class.cpp:2524]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor-CoreUObject.dll!UObjectLoadAllCompiledInDefaultProperties() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:745]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor-CoreUObject.dll!ProcessNewlyLoadedUObjects() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:830]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor-CoreUObject.dll!TBaseStaticDelegateInstance::ExecuteIfSafe() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\core\public\delegates\delegateinstancesimpl.h:1017]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor-Core.dll!TBaseMulticastDelegate::Broadcast() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\core\public\delegates\delegatesignatureimpl.inl:921]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor-Core.dll!FModuleManager::LoadModuleWithFailureReason() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\core\private\modules\modulemanager.cpp:461]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor-Projects.dll!FModuleDescriptor::LoadModulesForPhase() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\projects\private\moduledescriptor.cpp:398]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor-Projects.dll!FProjectManager::LoadModulesForProject() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\projects\private\projectmanager.cpp:53]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor.exe!FEngineLoop::LoadStartupModules() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2218]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor.exe!FEngineLoop::PreInit() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:1653]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor.exe!GuardedMain() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\launch\private\launch.cpp:117]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor.exe!GuardedMainWrapper() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor.exe!WinMain() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: UE4Editor.exe!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
[2016.09.26-19.24.11:711][  0]LogWindows:Error: kernel32.dll
[2016.09.26-19.24.11:711][  0]LogWindows:Error: ntdll.dll
[2016.09.26-19.24.11:711][  0]LogWindows:Error: ntdll.dll
[2016.09.26-19.24.11:711][  0]LogWindows:Error: 
[2016.09.26-19.24.11:732][  0]LogExit: Executing StaticShutdownAfterError
[2016.09.26-19.24.11:734][  0]LogWindows: FPlatformMisc::RequestExit(1)
[2016.09.26-19.24.11:734][  0]Log file closed, 09/26/16 15:24:11

That crash is on editor startup if you’re calling DisableProjection() in another actor’s constructor. It also crashes if you call it during gameplay (for example, in BeginPlay()). I’m unaware of any circumstances where this function can be called without causing a crash. This effectively makes it impossible to disable projection on Physics Constraint Components in any setting other than in blueprint (where the bDisableProjection flag can be accessed directly in the CDO. bDisableProjection has been marked as deprecated elsewhere.)

The problems with the PhysicsConstraintComponent go a lot deeper than this. The whole thing is a pretty catastrophic mess. A lot of this is PhysX’s fault, but not all of it.

  • Very few of the properties exposed in the editor correspond to values in C++. They change names randomly as they are passed through multiple layers of wrapping functions.
  • Many of the properties have custom editor representations, and as such are unlabelled. So it’s very hard to track down where they’re coming from, since they have no visible name to search for in code. And even if they do have visible names, the names are often localized overrides for the actual property names which have to be chased around in editor code.
  • Very few of the properties exposed in the editor are actually on the component. They’re spread around three or four separate classes and subobjects, many of which are EditInline, so their properties are all mixed together.
  • Many of the properties which are exposed to the editor are tied to deprecated values in code, and appear to have no effect when modified in code. For example, there is no way that I can see to set the target orientation drive to SLERP. To do this, you have to set the ConstraintInstance.AngularDriveMode_DEPRECATED to SLERP, but as you can see, it’s deprecated. Then you need to enable the Slerp drive, but SetAngularOrientationDrive only lets you set the swing and twist drives.
  • Many of the functions on the component cause linker errors if you dare to call them. Such as PhysicsConstraint->InitComponentConstraint(), which looks like it needs to be called after setting certain values for them to take effect. But doing so causes a linker error with an unresolved external symbol.
  • Because of the scattered mess of where all of these properties live, a lot of basic editor functionality doesn’t work.
  • You can’t create a new class which inherits from PhysicsConstraintComponent. You just end up with a on on liner errors with just an empty class.

Hi Teiwaz,

The crash that you are experiencing is due to there not being a valid Constraint Instance in the Physics Constraint Component that you are using. You can check to see if the Constraint Instance is valid before calling the DisableProjection() function to avoid this crash. For example, try using:

if (ThePCC->ConstraintInstance.IsValidConstraintInstance())
{
	ThePCC->ConstraintInstance.DisableProjection();
}

In my tests, this would not result in a crash if the Constraint Instance was not valid, but would work as expected if it was valid.

I did see the build errors that you mentioned when trying to create a custom Physics Constraint Component. I have entered ticket UE-36672 to see if we can improve this.

I will also try to dig into some of the other points that you raised as well.