Я впервые изучаю MonoGame, и я создал систему, которая генерирует словарь карт и порождает плитки рядом с игроком и удаляет их, когда они находятся вне диапазона.
Это работает, как и ожидалось, но после некоторого обхода я получаю эту ошибку:
System.ObjectDisposedException: 'Невозможно получить доступ к удаленному объекту. Название объекта: 'Icon'. '
Казалось бы, без рисунка. Он показывается в строке:
public Tile(int X, int Y, string Type)
Я новичок в объектно-ориентированном программировании, но не смог понять причины ошибки в сети, поскольку они казались не связанными. Если потребуется дополнительная информация, просто спросите, и я добавлю ее. Буду очень признателен за некоторую помощь.
Спрайт плитки:
//##Tile##
public class Tile : Game
{
//##Default Varibles##
public Vector2 Scale;
public Vector2 Position;
public Rectangle Rect;
//##Initialise##
public Vector2 GridPosition;
public Tile(int X, int Y, string Type)
{
Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace);
//Position
GridPosition = new Vector2(X, Y);
Position = new Vector2(MainGame.instance.Graphics.PreferredBackBufferWidth / 2 - MainGame.instance.AssetManager.TileTextureList[0].Width / 2 + X * 64, MainGame.instance.Graphics.PreferredBackBufferHeight / 2 - MainGame.instance.AssetManager.TileTextureList[0].Height / 2 + Y * 64);
//Rect
Rect = new Rectangle((int)Position.X, (int)Position.Y, MainGame.instance.AssetManager.TileTextureList[0].Width, MainGame.instance.AssetManager.TileTextureList[0].Height);
}
//##EveryFrame##
public void Update()
{
//Function Calls
//Update Rectangle
Rect.Location = new Point((int)Position.X, (int)Position.Y);
}
//##Draw##
public void Draw()
{
MainGame.instance.MainLayer.Draw(texture: MainGame.instance.AssetManager.TileTextureList[0], position: Position, color: Color.White);
}
}
Трассировка стека Думаю:
StackTrace: ' at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at ThisGame.Sprites.Tile..ctor(Int32 X, Int32 Y, String Type) in C:\Users\User\Desktop\Coding\C# Projects\MonoGame\FalseGold\FalseGold\Sprites.cs:line 226
at ThisGame.Functions.LoadTiles() in C:\Users\User\Desktop\Coding\C# Projects\MonoGame\FalseGold\FalseGold\Functions.cs:line 80
at ThisGame.Sprites.Update() in C:\Users\User\Desktop\Coding\C# Projects\MonoGame\FalseGold\FalseGold\Sprites.cs:line 30
at ThisGame.MainGame.Update(GameTime gameTime) in C:\Users\User\Desktop\Coding\C# Projects\MonoGame\FalseGold\FalseGold\Game.cs:line 101
at Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime)
at Microsoft.Xna.Framework.Game.Tick()
at MonoGame.Framework.WinFormsGameWindow.TickOnIdle(Object sender, EventArgs e)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at MonoGame.Framework.WinFormsGameWindow.RunLoop()
at MonoGame.Framework.WinFormsGamePlatform.RunLoop()
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
at Microsoft.Xna.Framework.Game.Run()
at ThisGame.Program.Main() in C:\Users\User\Desktop\Coding\C# Projects\MonoGame\FalseGold\FalseGold\Program.cs:line 12'
Exception thrown: 'System.ObjectDisposedException' in System.Drawing.dll
An unhandled exception of type 'System.ObjectDisposedException' occurred in System.Drawing.dll
Cannot access a disposed object.
Игра работает: Ссылка
Если я немного не хожу, это не сломается sh.