Implement IDisposable on Window/WindowArea
This commit is contained in:
parent
9d01f77625
commit
2dd80cdd0d
@ -2,7 +2,7 @@
|
||||
|
||||
namespace TrueCraft.API.Windows
|
||||
{
|
||||
public interface IWindow
|
||||
public interface IWindow : IDisposable
|
||||
{
|
||||
event EventHandler<WindowChangeEventArgs> WindowChange;
|
||||
|
||||
@ -33,4 +33,4 @@ namespace TrueCraft.API.Windows
|
||||
/// </summary>
|
||||
void CopyToInventory(IWindow inventoryWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace TrueCraft.API.Windows
|
||||
{
|
||||
public interface IWindowArea
|
||||
public interface IWindowArea : IDisposable
|
||||
{
|
||||
event EventHandler<WindowChangeEventArgs> WindowChange;
|
||||
|
||||
@ -17,4 +17,4 @@ namespace TrueCraft.API.Windows
|
||||
void CopyTo(IWindowArea area);
|
||||
int MoveOrMergeItem(int index, ItemStack item, IWindowArea from);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
newEntity["Items"] = entityAdjacent;
|
||||
world.SetTileEntity(adjacent, newEntity);
|
||||
}
|
||||
}; // TODO: Memory leak here, make windows implement IDisposable
|
||||
};
|
||||
user.OpenWindow(window);
|
||||
return false;
|
||||
}
|
||||
@ -224,4 +224,4 @@ namespace TrueCraft.Core.Logic.Blocks
|
||||
base.BlockMined(descriptor, face, world, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using TrueCraft.API;
|
||||
|
||||
namespace TrueCraft.Core.Windows
|
||||
{
|
||||
public abstract class Window : IWindow
|
||||
public abstract class Window : IWindow, IDisposable
|
||||
{
|
||||
public abstract IWindowArea[] WindowAreas { get; protected set; }
|
||||
|
||||
@ -141,5 +141,14 @@ namespace TrueCraft.Core.Windows
|
||||
if (WindowChange != null)
|
||||
WindowChange(this, e);
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
for (int i = 0; i < WindowAreas.Length; i++)
|
||||
{
|
||||
WindowAreas[i].Dispose();
|
||||
}
|
||||
WindowChange = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,5 +96,10 @@ namespace TrueCraft.Core.Windows
|
||||
if (WindowChange != null)
|
||||
WindowChange(this, e);
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
WindowChange = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,6 +216,7 @@ namespace TrueCraft
|
||||
if (!clientInitiated)
|
||||
QueuePacket(new CloseWindowPacket(CurrentWindow.ID));
|
||||
CurrentWindow.CopyToInventory(Inventory);
|
||||
CurrentWindow.Dispose();
|
||||
CurrentWindow = InventoryWindow;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user