From 1130eef3108784823a91c4e8dd35d3f916078058 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Fri, 14 Jun 2019 12:22:55 +0300 Subject: [PATCH] (51d0e9a7a) Fixed crashing when firing a revolver in the sub editor. Closes #1631 --- .../Source/Items/Components/Holdable/RangedWeapon.cs | 1 + .../Source/Items/Components/Projectile.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs index de0f31eb8..552e5d13e 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs @@ -170,6 +170,7 @@ namespace Barotrauma.Items.Components projectile.Item.SetTransform(projectilePos, rotation); projectile.Use(deltaTime); + if (projectile.Item.Removed) { return true; } projectile.User = character; projectile.Item.body.ApplyTorque(projectile.Item.body.Mass * degreeOfFailure * Rand.Range(-10.0f, 10.0f)); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs index 12375fecf..d155ff108 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs @@ -275,7 +275,14 @@ namespace Barotrauma.Items.Components //the raycast didn't hit anything -> the projectile flew somewhere outside the level and is permanently lost if (!hitSomething) { - Entity.Spawner.AddToRemoveQueue(item); + if (Entity.Spawner == null) + { + item.Remove(); + } + else + { + Entity.Spawner.AddToRemoveQueue(item); + } } }