Broken Ragdoll Transform?

Hi, I’ve been trying to fix this myself for days and it’s beginning to drive me insane…

I will try to stick to the essential information and not write an essay here right from the start. If you need more info, I’m glad to provide it.

My setup is this: a landscape with about 100 vs 100 characters killing each other. My testing arsenal contains bows, magic and melee weapons at the moment. No problems with the ranged stuff, but melee weapons tend to break the game completely. My melee implementation is based on “manual” sweeping from the weapons Tick function to determine if the weapon hits something in a given frame.

After lots of testing I can say that the bug happens only when characters are going (or have already gone?) ragdoll. Without dead characters turning into ragdolls there is no bug.

So it usually happens a while after the two groups have clashed and there are already corpses on the ground. Then suddenly the game/editor freezes and after half a minute or so I get this error:

LogCore:Error: ConvertQueryImpactHit() received NaN/Inf for position: -nan(ind) -nan(ind) -nan(ind)

After that the game continues, but the whole physics/collision part is broken somehow. Projectiles (arrows and magic) suddenly don’t hit the ground anymore but fall through it. Melee sweeps start hitting their carrier instantly on performing an attack even though that carrier is supposed to be ignored during the sweeps. On top of that the console gets spammed with more error messages looking like this:

LogCollision:Error: GeomSweepSingle resulted in a NaN/INF in PHit!

The frame rate also drops significantly after the initial error, probably because of the console spam that follows it. After the first 50 (+/-) times the message above got spammed, there is this section about a broken bounding box:

LogOutputDevice:Warning: === Handled error: ===
Ensure condition failed: !Primitive->Bounds.BoxExtent.ContainsNaN() && !Primitive->Bounds.Origin.ContainsNaN() && !FMath::IsNaN(Primitive->Bounds.SphereRadius) && FMath::IsFinite(Primitive->Bounds.SphereRadius) [File:D:\Build\++UE4+Release-4.12+Compile\Sync\Engine\Source\Runtime\Renderer\Private\RendererScene.cpp] [Line: 800]
Nans found on Bounds for Primitive CharacterMesh0: Origin X=-nan(ind) Y=-nan(ind) Z=-nan(ind), BoxExtent X=nan Y=nan Z=nan, SphereRadius -nan(ind)
Stack: 
UE4Editor-Core.dll!FWindowsPlatformStackWalk::StackWalkAndDump() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\private\windows\windowsplatformstackwalk.cpp:183]
UE4Editor-Core.dll!FDebug::EnsureFailed() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\private\misc\outputdevice.cpp:327]
UE4Editor-Core.dll!FDebug::OptionallyLogFormattedEnsureMessageReturningFalse() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\private\misc\outputdevice.cpp:451]
UE4Editor-Renderer.dll!FScene::UpdatePrimitiveTransform() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\renderer\private\rendererscene.cpp:799]
UE4Editor-Engine.dll!UPrimitiveComponent::SendRenderTransform_Concurrent() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\components\primitivecomponent.cpp:383]
UE4Editor-Engine.dll!UActorComponent::DoDeferredRenderUpdates_Concurrent() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\components\actorcomponent.cpp:1251]
UE4Editor-Engine.dll!<lambda_1c27e0d8d47d1db9d2f7e512dcaa630c>::operator()() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:857]
UE4Editor-Engine.dll!ParallelForWithPreWork() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\public\async\parallelfor.h:214]
UE4Editor-Engine.dll!UWorld::SendAllEndOfFrameUpdates() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:871]
UE4Editor-Renderer.dll!FRendererModule::BeginRenderingViewFamily() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\renderer\private\scenerendering.cpp:1998]
UE4Editor-Engine.dll!UGameViewportClient::Draw() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\gameviewportclient.cpp:1096]
UE4Editor-Engine.dll!FViewport::Draw() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\unrealclient.cpp:1149]
UE4Editor-UnrealEd.dll!UEditorEngine::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1531]
UE4Editor-UnrealEd.dll!UUnrealEdEngine::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:368]
UE4Editor.exe!FEngineLoop::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2775]
UE4Editor.exe!GuardedMain() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\launch.cpp:148]
UE4Editor.exe!GuardedMainWrapper() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor.exe!WinMain() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]
UE4Editor.exe!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32.dll
ntdll.dll
ntdll.dll
LogStats:                SubmitErrorReport -  0.000 s
LogStats:                    SendNewReport -  7.685 s
LogStats:             FDebug::EnsureFailed - 25.510 s

And after that,

LogCollision:Error: GeomSweepSingle resulted in a NaN/INF in PHit!

keeps spamming on indefinitely.

After using the debugger, I think what happens is that a ragdoll’s head-bone gets an invalid location for some reason, which then causes the character-mesh’s bounds to become invalid as well. Maybe the broken physics behavior afterwards are caused by some shape(s) becoming infinitely big or something?.. I don’t know, if other bone-transforms can become NaN (whatever that actually means) as well. So far I’ve only seen it happening to the head.

And something really weird: I can’t be 100% sure this is not some coincidence, but it looks very much like the bug stops happening when I use this line:

UE_LOG(MyLog, Warning, TEXT("sweep hit (%i): %s, %s, %s, %s, %s, %s, %s, %f, %s"), j, *Carrier->GetName(), *GetName(), *allHits[j].Actor->GetName(), *allHits[j].Component->GetName(), *allHits[j].BoneName.ToString(), *allHits[j].ImpactPoint.ToString(), *allHits[j].Location.ToString(), allHits[j].Time, (allHits[j].Time == 0.f) ? TEXT(" - INITIAL") : TEXT(""))

after every melee-sweep to display info about it. I thought I might find some hint what’s causing the problem, but instead that line seems to fix it or at least reduces the chance for it to happen drastically. So, since that line doesn’t actually “do” anything other than read some values and log them to the console, I can only imagine that the delay it causes somehow prevents the bug. The sweeping code takes 0 to 1 ms without the UE_LOGs, and something from 5 to 15 with the UE_LOGs.

Does this make any sense to anyone? Please help fix this properly! I can’t just spam the console or create any artificial delays inside my code and hope that the problem is solved without having an idea what’s going on…

More testing has shown that not just a single bone of a single ragdoll gets a NaN location, but pretty much every bone of almost every ragdoll has this problem after the initial freeze and the first error message. Maybe it starts with one and then kind of spreads… I have absolutely no idea what’s going on here. Help please!!

I wrote some code to check every character’s bone locations’ on every Tick() call, report any NaN to the console and destroy the character’s SkeletalMeshComponent after finding something. And it looks like removing the ragdolls with invalid bone locations does NOT stop the broken physics/collision behavior, and the console still gets spammed with

LogCollision:Error: GeomSweepSingle resulted in a NaN/INF in PHit!

I keep changing small things, but I just can’t find an actual cause for this… Some changes may increase or decrease the chance for this weird problem to occur, but I still don’t what’s actually going wrong here.

Is it possible that these errors can always happen when lots of ragdolls start piling up literally on top of each other??
Is the physics engine simply unable to seperate all the jointed shapes?

I really need some help here…

Please let me know if you figure this out. I am having a similar problem. I have 2 waves fighting each other and when they start dying and ragdoll, eventually it seems that it will cause a crash with a similar error in the log. The strange part is that I also had one clean run through where I went through 18 waves and no crash at all… Don’t know what was different about that time though… I hadn’t changed anything I don’t think.

I think I narrowed it down to where I apply an impulse to ragdolls by code to simulate the impact of a melee hit. I did something similar with projectile hits, but I guess maybe the values in the melee equations produce some broken results (like extremely high?..) that cause the ragdolls to become corrupted. I haven’t monitored those values yet to verify this, but I disabled the impulse-code completely for the moment and I think the errors have stopped. Hope this helps.

This comment was everything that I needed to heard! Thank you so much for posting this. After digging around in many different areas of my code, googling and so on your comment gave me a direction. I removed parts of my code of a plugin that I’m developing and finally founded the problem! Thank you again!

It was, indeed, a function that doesn’t applied any force, instead, removed it, 'cause in Engine code, that piece was commented, and for some weird reason, got NaN on my primitives too! It shouden’t be zero anyway, but the minimum 5.72. Thanks!

No problem, glad to be of help :slight_smile:

I still have the melee-impulses disabled, because I have been working on so many other parts of my project in the last months. My suspicion lately was that the cause of the broken transforms is ultimately the applying of a zero-magnitude impulse. Is that about right?

Yea I discovered the solution in mine as well. If the melee component has collision set to something other than no collision and they are close enough for the capsules to overlap it will crash. You have to set the collision of it to no collision. Hope that helps someone.

For me it was, but I’m working with vehicles. The property in question is CamberStiffenessPerUnitGravity, which is commented by default on Engine code, but, since I’m trying to expose these portion of PhysX to the Engine, just ‘setuped’ it to 0 ZERO, by default, but, it I was getting the NaN error, not sure why it happened. So I mixed my vehicles with standard wheels, and my derived one, and found that the standard one has a value by default on PhysX side that is 5.72, applying 0 to it and you get NaN. So, grabbed that value, applied to my wheels and ‘DONE’! It Worked!

I’m having a similar issue with rag dolls. I’ll try adjusting the impulse strength.

Here is my stack:

Error: === Critical error: ===
[2017.11.07-17.11.18:188][814]LogWindows: Error:
[2017.11.07-17.11.18:188][814]LogWindows: Error: Ensure condition failed: !Primitive->Bounds.BoxExtent.ContainsNaN() && !Primitive->Bounds.Origin.ContainsNaN() && !FMath::IsNaN(Primitive->Bounds.SphereRadius) && FMath::IsFinite(Primitive->Bounds.SphereRadius) [File:D:\Downloads\UnrealEngine-4.17\Engine\Source\Runtime\Renderer\Private\RendererScene.cpp] [Line: 877]
[2017.11.07-17.11.18:188][814]LogWindows: Error: Nans found on Bounds for Primitive CharacterMesh0: Origin X=-nan Y=-nan Z=-nan, BoxExtent X=nan Y=nan Z=nan, SphereRadius -nan
[2017.11.07-17.11.18:188][814]LogWindows: Error:
[2017.11.07-17.11.18:188][814]LogWindows: Error:
[2017.11.07-17.11.18:189][814]LogWindows: Error:
[2017.11.07-17.11.18:189][814]LogWindows: Error: Crash in runnable thread TaskGraphThreadHP 3
[2017.11.07-17.11.18:248][814]LogExit: Executing StaticShutdownAfterError
[2017.11.07-17.11.18:248][814]LogWindows: FPlatformMisc::RequestExit(1)