[BUG] Closing a panel randomly throws a Nullpointer inside ItemShapeSelectedItemView.cs

The error points to

itemInfo.Item.TryGetAttributeValue<ItemShape>(ItemShapeGridData.ShapeAttributeName...

NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateInventorySystem.UI.Item.ItemViewModules.ItemShapeSelectedItemView.UpdateFilter (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, UnityEngine.Vector2Int itemPosition, UnityEngine.Color color, System.Boolean enableFilter) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewModules/ItemShapeSelectedItemView.cs:89)
Opsive.UltimateInventorySystem.UI.Item.ItemViewModules.ItemShapeSelectedItemView.Select (System.Boolean select) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewModules/ItemShapeSelectedItemView.cs:80)
Opsive.UltimateInventorySystem.UI.Views.View.Select (System.Boolean select) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Views/View.cs:97)
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlot.OnDeselect (UnityEngine.EventSystems.BaseEventData eventData) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlot.cs:122)
Opsive.UltimateInventorySystem.UI.Panels.ItemViewSlotContainers.ItemViewSlotsContainerPanelBinding.OnClose () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ItemViewSlotContainers/ItemViewSlotsContainerPanelBinding.cs:138)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanel.Close (System.Boolean selectPrevious) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanel.cs:347)
_Project.Scripts.ThirdParty.OpsiveAssets.Inventory.Ui.ButtonsOpenClosePanelBio.HandleButtonClicked (System.Int32 i) (at Assets/_Project/Scripts/ThirdParty/OpsiveAssets/Inventory/Ui/ButtonsOpenClosePanelBio.cs:119)
_Project.Scripts.ThirdParty.OpsiveAssets.Inventory.Ui.ButtonsOpenClosePanelBio+<>c__DisplayClass6_0.<Initialize>b__0 () (at Assets/_Project/Scripts/ThirdParty/OpsiveAssets/Inventory/Ui/ButtonsOpenClosePanelBio.cs:85)
UnityEngine.Events.InvokableCall.Invoke () (at <1d3dacd00ce441dc8c61d528a2193088>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <1d3dacd00ce441dc8c61d528a2193088>:0)
UnityEngine.UI.Button.Press () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)
 
Perhaps adding this active in hierarchy check inside Select fixes it, Im still testing...

public override void Select(bool select)
{
if (ItemShapeGrid == null) { return; }

if (!gameObject.activeInHierarchy) return;


if (select) {
var itemInfo = m_ItemShapeItemView.IsItemSelectable ? ItemInfo : ItemInfo.None;
UpdateFilter(itemInfo, m_ItemShapeItemView.AnchorPosition, m_SelectedColor, select);
} else {
UpdateFilter(ItemInfo, m_ItemShapeItemView.AnchorPosition, m_SelectedColor, select);
}
}
 
I'll be adding a null check here just in case too.

Code:
protected virtual void UpdateFilter(ItemInfo itemInfo, Vector2Int itemPosition, Color color, bool enableFilter)
        {
            if (itemInfo.Item == null || ItemShapeGridData == null ||
                itemInfo.Item.TryGetAttributeValue<ItemShape>(ItemShapeGridData.ShapeAttributeName, out var itemShape) == false
                || itemShape.Count <= 1) {
 
I think the issue was because I call panel.Close and by default it selects another panel but my goal was to close all.

If I call panel.Close(false); I think the issue wont appear, I have not tested though.
 
Top