From b6641c485328da6de084a0e00cb629cb41eda6bb Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Thu, 16 Sep 2021 23:55:37 -0700 Subject: [PATCH] fix: Don't crash the world if a stealable artifact fails to construct (#789) --- .../StealableArtifactsSpawner.cs | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Projects/UOContent/Items/Decoration Artifacts/StealableArtifactsSpawner.cs b/Projects/UOContent/Items/Decoration Artifacts/StealableArtifactsSpawner.cs index 8865c48c8..d7e34a96e 100644 --- a/Projects/UOContent/Items/Decoration Artifacts/StealableArtifactsSpawner.cs +++ b/Projects/UOContent/Items/Decoration Artifacts/StealableArtifactsSpawner.cs @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; +using Server.Logging; using Server.Utilities; namespace Server.Items { public class StealableArtifactsSpawner : Item { + private static readonly ILogger logger = LogFactory.GetLogger(typeof(StealableArtifactsSpawner)); + private static Type[] m_TypesOfEntries; private StealableInstance[] m_Artifacts; @@ -342,17 +345,25 @@ namespace Server.Items public Item CreateInstance() { - var item = Type.CreateInstance(); - - if (Hue > 0) + try { - item.Hue = Hue; + var item = Type.CreateInstance(); + + if (Hue > 0) + { + item.Hue = Hue; + } + + item.Movable = false; + item.MoveToWorld(Location, Map); + + return item; + } + catch (Exception e) + { + logger.Warning(e, $"Failed to construct stealable artifact: {Type.FullName}"); + return null; } - - item.Movable = false; - item.MoveToWorld(Location, Map); - - return item; } }