I have been receiving the following warning/error message on my game after it has been running for 10-15 seconds, this even occurs when there is no interaction with the game:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.Drawing.dll
Additional information: The operation completed successfully
I was wondering if I needed to call a Dispose()
method in order to remove the objects that are not being used as they are being loaded even when they have been removed from the game world?
I have all objects stored as a list (shown below)
class Items
{
public static List<Obj> objList = new List<Obj>();
public static void Initialize()
{
//The Player
objList.Add(new Player(new Vector2(50, 50)));
//The Enemies
objList.Add(new Enemy(new Vector2(500, 400)));
objList.Add(new Enemy(new Vector2(600, 200)));
//The Collectibles
objList.Add(new BlueBall(new Vector2(300, 400)));
objList.Add(new GreenBall(new Vector2(350, 100)));
objList.Add(new OrangeBall(new Vector2(65000, 250)));
objList.Add(new PinkBall(new Vector2(100, 400)));
objList.Add(new RedBall(new Vector2(600, 400)));
objList.Add(new YellowBall(new Vector2(500, 250)));
}
I then call Items.Initialize
in the Game1 class
I currently have a collision method as well that is called once an object collides with another and I am thinking that this may be causing the issue but I am not 100%. As my game stands, I am currently only setting the objects state to = alive = false;
in order to 'kill' them and remove them from the screen, this can be seen below with an example showing the collision of the Player and an Enemy:
//Collision with enemy
Enemy enemy = CheckCollisionAgainst<Enemy>();
if (enemy != null)
{
gameOver.Play();
alive = false;
}
I've been stuck with this error now and have not been able to find a solution to stop it from happening. As I stated earlier, it occurs after the game has been running for 10-15 seconds so I am unable to progress with any other features until this error is fixed.
I appreciate any help and thanks in advance.