Physics error checks & logging

This commit is contained in:
Joonas Rikkonen
2018-07-30 14:31:30 +03:00
parent 7acd3f746d
commit 86df5f6b1a
2 changed files with 23 additions and 6 deletions

View File

@@ -480,9 +480,7 @@ namespace Barotrauma
Vector2 avgContactNormal = Vector2.Zero;
foreach (Contact levelContact in levelContacts)
{
Vector2 contactNormal;
FixedArray2<Vector2> temp;
levelContact.GetWorldManifold(out contactNormal, out temp);
levelContact.GetWorldManifold(out Vector2 contactNormal, out FixedArray2<Vector2> temp);
//if the contact normal is pointing from the limb towards the level cell it's touching, flip the normal
VoronoiCell cell = levelContact.FixtureB.UserData is VoronoiCell ?
@@ -504,7 +502,21 @@ namespace Barotrauma
float contactDot = Vector2.Dot(Body.LinearVelocity, -avgContactNormal);
if (contactDot > 0.0f)
{
Body.LinearVelocity -= Vector2.Normalize(Body.LinearVelocity) * contactDot;
Vector2 velChange = Vector2.Normalize(Body.LinearVelocity) * contactDot;
if (!MathUtils.IsValid(velChange))
{
GameAnalyticsManager.AddErrorEventOnce(
"SubmarineBody.HandleLimbCollision:" + submarine.ID,
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
"Invalid velocity change in SubmarineBody.HandleLimbCollision (submarine velocity: " + Body.LinearVelocity
+ ", avgContactNormal: " + avgContactNormal
+ ", contactDot: " + contactDot
+ ", velChange: " + velChange + ")");
return;
}
Body.LinearVelocity -= velChange;
float damageAmount = contactDot * Body.Mass / limb.character.Mass;

View File

@@ -184,11 +184,16 @@ namespace Barotrauma
}
catch (Exception e)
{
DebugConsole.ThrowError("Exception in PhysicsBody.Enabled = "+value+" ("+isPhysEnabled+")",e);
if (UserData!=null) DebugConsole.NewMessage("PhysicsBody UserData: "+UserData.GetType().ToString(), Color.Red);
DebugConsole.ThrowError("Exception in PhysicsBody.Enabled = " + value + " (" + isPhysEnabled + ")", e);
if (UserData != null) DebugConsole.NewMessage("PhysicsBody UserData: " + UserData.GetType().ToString(), Color.Red);
if (GameMain.World.ContactManager == null) DebugConsole.NewMessage("ContactManager is null!", Color.Red);
else if (GameMain.World.ContactManager.BroadPhase == null) DebugConsole.NewMessage("Broadphase is null!", Color.Red);
if (body.FixtureList == null) DebugConsole.NewMessage("FixtureList is null!", Color.Red);
if (UserData is Entity entity)
{
DebugConsole.NewMessage("Entity \"" + entity.ToString() + "\" removed!", Color.Red);
}
}
}
}