Improves item disposal in inventory category
Ensures items are returned to the shared item pool or disposed of properly when clearing an inventory category.
This commit is contained in:
@@ -508,7 +508,44 @@ public class InventoryCategoryNode : InventoryCategoryNodeBase
|
||||
|
||||
using (_itemGridNode.DeferRecalculateLayout())
|
||||
{
|
||||
_itemGridNode.Clear();
|
||||
ReturnItemsToPool();
|
||||
_itemGridNode.ClearListOnly();
|
||||
}
|
||||
}
|
||||
|
||||
private void ReturnItemsToPool()
|
||||
{
|
||||
var nodes = _itemGridNode.Nodes;
|
||||
for (int i = 0; i < nodes.Count; i++)
|
||||
{
|
||||
if (nodes[i] is not InventoryDragDropNode itemNode)
|
||||
continue;
|
||||
|
||||
if (SharedItemPool != null)
|
||||
{
|
||||
if (!SharedItemPool.TryReturn(itemNode))
|
||||
{
|
||||
try
|
||||
{
|
||||
itemNode.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Services.Logger.Error(ex, "[InventoryCategoryNode] Error disposing overflow item node");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
itemNode.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Services.Logger.Error(ex, "[InventoryCategoryNode] Error disposing item node (no pool)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,6 +229,21 @@ public abstract class DeferrableLayoutListNode : SimpleComponentNode
|
||||
RecalculateLayout();
|
||||
}
|
||||
|
||||
public void ClearListOnly()
|
||||
{
|
||||
_suppressRecalculateLayout = true;
|
||||
try
|
||||
{
|
||||
NodeList.Clear();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_suppressRecalculateLayout = false;
|
||||
}
|
||||
|
||||
RecalculateLayout();
|
||||
}
|
||||
|
||||
public delegate TU CreateNewNode<in T, out TU>(T data) where TU : NodeBase;
|
||||
|
||||
public delegate T GetDataFromNode<out T, in TU>(TU node) where TU : NodeBase;
|
||||
|
||||
Reference in New Issue
Block a user