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;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace TrueCraft.API.Windows
|
||||
{
|
||||
public interface IWindowArea
|
||||
public interface IWindowArea : IDisposable
|
||||
{
|
||||
event EventHandler<WindowChangeEventArgs> WindowChange;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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