(652745ae0) Fix a crash due to invalid physics when scaling the Mudraptor. If the ragdoll still has invalid settings after trying to reset it, just freeze it to prevent crashing. Return boolean and make CheckValidity public so that we can check and react to the invalid ragdoll state elsewhere.

This commit is contained in:
Joonas Rikkonen
2019-03-26 17:08:53 +02:00
parent 56d1f5a054
commit 705d05a308
2 changed files with 54 additions and 15 deletions

View File

@@ -118,6 +118,19 @@ namespace Barotrauma
instance = this;
}
private void Reset()
{
AnimParams.ForEach(a => a.Reset(true));
RagdollParams.Reset(true);
RagdollParams.ClearHistory();
CurrentAnimation.ClearHistory();
if (!character.Removed)
{
character.Remove();
}
character = null;
}
public override void Deselect()
{
base.Deselect();
@@ -128,15 +141,7 @@ namespace Barotrauma
isEndlessRunner = false;
if (character != null)
{
AnimParams.ForEach(a => a.Reset(true));
RagdollParams.Reset(true);
RagdollParams.ClearHistory();
CurrentAnimation.ClearHistory();
if (!character.Removed)
{
character.Remove();
}
character = null;
Reset();
}
GameMain.World.ProcessChanges();
}
@@ -393,6 +398,12 @@ namespace Barotrauma
}
if (!isFreezed)
{
if (character.AnimController.Invalid)
{
Reset();
SpawnCharacter(currentCharacterConfig);
}
Submarine.MainSub.SetPrevTransform(Submarine.MainSub.Position);
Submarine.MainSub.Update((float)deltaTime);

View File

@@ -1031,7 +1031,9 @@ namespace Barotrauma
public void Update(float deltaTime, Camera cam)
{
if (!character.Enabled || Frozen) return;
if (!character.Enabled || Frozen || Invalid) return;
CheckValidity();
CheckValidity();
@@ -1295,17 +1297,42 @@ namespace Barotrauma
UpdateProjSpecific(deltaTime);
}
private void CheckValidity()
public bool Invalid { get; private set; }
private int validityResets;
private bool CheckValidity()
{
CheckValidity(Collider);
bool isColliderValid = CheckValidity(Collider);
bool limbsValid = true;
foreach (Limb limb in limbs)
{
if (limb.body == null || !limb.body.Enabled) { continue; }
CheckValidity(limb.body);
if (!CheckValidity(limb.body))
{
limbsValid = false;
break;
}
}
bool isValid = isColliderValid && limbsValid;
if (!isValid)
{
validityResets++;
if (validityResets > 1)
{
Invalid = true;
DebugConsole.ThrowError("Invalid ragdoll physics. Ragdoll freezed to prevent crashes.");
Collider.SetTransform(Vector2.Zero, 0.0f);
foreach (Limb limb in Limbs)
{
limb.body.SetTransform(Collider.SimPosition, 0.0f);
limb.body.ResetDynamics();
}
Frozen = true;
}
}
return isValid;
}
private void CheckValidity(PhysicsBody body)
private bool CheckValidity(PhysicsBody body)
{
string errorMsg = null;
string bodyName = body.UserData is Limb ? "Limb" : "Collider";
@@ -1357,8 +1384,9 @@ namespace Barotrauma
limb.body.ResetDynamics();
}
SetInitialLimbPositions();
return;
return false;
}
return true;
}
partial void UpdateProjSpecific(float deltaTime);