From fde372745305488d56ea5e4a009b4164dd8d4b15 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 2 Jun 2020 17:02:42 +0100 Subject: [PATCH] avoid null refs on part inventory, that can happen if only using default animations names for example --- .../Framework/Scenes/Scripting/ScriptUtils.cs | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs index 94653d54d5..d6b8b573b0 100644 --- a/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs +++ b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs @@ -64,22 +64,20 @@ namespace OpenSim.Region.Framework.Scenes.Scripting /// public static UUID GetAssetIdFromKeyOrItemName(SceneObjectPart part, string identifier) { - UUID key; - // if we can parse the string as a key, use it. // else try to locate the name in inventory of object. found returns key, // not found returns UUID.Zero - if (!UUID.TryParse(identifier, out key)) + if (UUID.TryParse(identifier, out UUID key)) + return key; + + if (part.Inventory != null) { TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier); - if (item != null) - key = item.AssetID; - else - key = UUID.Zero; + return item.AssetID; } - return key; + return UUID.Zero; } /// @@ -92,28 +90,33 @@ namespace OpenSim.Region.Framework.Scenes.Scripting /// public static UUID GetAssetIdFromKeyOrItemName(SceneObjectPart part, string identifier, AssetType type) { - UUID key; - if (UUID.TryParse(identifier, out key)) + if (UUID.TryParse(identifier, out UUID key)) return key; - TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier); - if (item != null && item.Type == (int)type) - return item.AssetID; + if (part.Inventory != null) + { + TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier); + if (item != null && item.Type == (int)type) + return item.AssetID; + } return UUID.Zero; } public static UUID GetAssetIdFromKeyOrItemName(SceneObjectPart part, SceneObjectPart host, string identifier, AssetType type) { - UUID key; - if (UUID.TryParse(identifier, out key)) + if (UUID.TryParse(identifier, out UUID key)) return key; - TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier); - if (item != null && item.Type == (int)type) - return item.AssetID; + TaskInventoryItem item; + if (part.Inventory != null) + { + item = part.Inventory.GetInventoryItem(identifier); + if (item != null && item.Type == (int)type) + return item.AssetID; + } - if (part.LocalId != host.LocalId) + if (part.LocalId != host.LocalId && host.Inventory != null) { item = host.Inventory.GetInventoryItem(identifier); if (item != null && item.Type == (int)type)