(7e32870a0) Check that item has a non-zero mass before applying water forces (couldn't reproduce it, but had a debug assertion fail due to the mass of an alien artifact being 0), validate clamped force before attempting to apply it

This commit is contained in:
Joonas Rikkonen
2019-04-03 16:23:37 +03:00
parent 98cf26178f
commit abad70f0c1
4 changed files with 29 additions and 7 deletions
@@ -682,6 +682,25 @@ namespace Barotrauma
} }
}; };
//spacing
new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), generalLayoutGroup.RectTransform), style: null);
new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomLeft),
TextManager.Get("Cancel"), style: "GUIButtonLarge")
{
IgnoreLayoutGroups = true,
OnClicked = (x, y) =>
{
if (UnsavedSettings)
{
LoadPlayerConfig();
}
if (Screen.Selected == GameMain.MainMenuScreen) GameMain.MainMenuScreen.ReturnToMainMenu(null, null);
GUI.SettingsMenuOpen = false;
return true;
}
};
applyButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomRight), applyButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomRight),
TextManager.Get("ApplySettingsButton"), style: "GUIButtonLarge") TextManager.Get("ApplySettingsButton"), style: "GUIButtonLarge")
{ {
@@ -26,10 +26,6 @@ namespace Barotrauma.Items.Components
private float blinkTimer; private float blinkTimer;
private bool itemLoaded;
private float blinkTimer;
public PhysicsBody ParentBody; public PhysicsBody ParentBody;
[Editable(MinValueFloat = 0.0f, MaxValueFloat = 2048.0f), Serialize(100.0f, true)] [Editable(MinValueFloat = 0.0f, MaxValueFloat = 2048.0f), Serialize(100.0f, true)]
@@ -1077,7 +1077,7 @@ namespace Barotrauma
} }
ApplyStatusEffects(!waterProof && inWater ? ActionType.InWater : ActionType.NotInWater, deltaTime); ApplyStatusEffects(!waterProof && inWater ? ActionType.InWater : ActionType.NotInWater, deltaTime);
if (body == null || !body.Enabled || !inWater || ParentInventory != null) return; if (body == null || !body.Enabled || !inWater || ParentInventory != null || Removed) { return; }
ApplyWaterForces(); ApplyWaterForces();
CurrentHull?.ApplyFlowForces(deltaTime, this); CurrentHull?.ApplyFlowForces(deltaTime, this);
@@ -1116,6 +1116,11 @@ namespace Barotrauma
/// </summary> /// </summary>
private void ApplyWaterForces() private void ApplyWaterForces()
{ {
if (body.Mass <= 0.0f)
{
return;
}
float forceFactor = 1.0f; float forceFactor = 1.0f;
if (CurrentHull != null) if (CurrentHull != null)
{ {
@@ -646,7 +646,6 @@ namespace Barotrauma
/// </summary> /// </summary>
public void ApplyForce(Vector2 force, float maxVelocity) public void ApplyForce(Vector2 force, float maxVelocity)
{ {
if (!IsValidValue(force, "force", -1e10f, 1e10f)) return;
if (!IsValidValue(maxVelocity, "max velocity")) return; if (!IsValidValue(maxVelocity, "max velocity")) return;
Vector2 velocityAddition = force / Mass * (float)Timing.Step; Vector2 velocityAddition = force / Mass * (float)Timing.Step;
@@ -657,7 +656,10 @@ namespace Barotrauma
{ {
newVelocity = newVelocity.ClampLength(maxVelocity); newVelocity = newVelocity.ClampLength(maxVelocity);
} }
body.ApplyForce((newVelocity - body.LinearVelocity) * Mass / (float)Timing.Step);
Vector2 clampedForce = (newVelocity - body.LinearVelocity) * Mass / (float)Timing.Step;
if (!IsValidValue(force, "clamped force", -1e10f, 1e10f)) return;
body.ApplyForce(force);
} }
public void ApplyForce(Vector2 force, Vector2 point) public void ApplyForce(Vector2 force, Vector2 point)