Christian Boman
Christian Boman

Reputation: 43

Trouble starting Debug for my game in XNA (vb.net)

I've been working on a game project in XNA (vb.net) for a few years now, but I don't have a formal education and so I'm learning while trying. This means I might be writing code inefficiently or simply wrong (good to take into consideration). To my problem:

Today, for the first time, when I start up the debug I get an error before the first frame is drawn (a white window appear). it's highlighting my game.Run() with the error System.OutOfMemoryException. When I copy it to clipboard it says:

System.OutOfMemoryException was unhandled
HResult=-2147024882
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=WindowsGame2
StackTrace:
     at WindowsGame2.Game1.Draw(GameTime gameTime)
     at Microsoft.Xna.Framework.Game.DrawFrame()
     at Microsoft.Xna.Framework.Game.Tick()
     at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
     at Microsoft.Xna.Framework.GameHost.OnIdle()
     at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
     at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object   sender, EventArgs e)
     at   System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNat  iveMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
     at   System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Unsafe  NativeMethods.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 Microsoft.Xna.Framework.WindowsGameHost.Run()
     at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
     at Microsoft.Xna.Framework.Game.Run()
     at WindowsGame2.Program.Main(String[] args) in C:\Projects  \WindowsGame2\WindowsGame2\WindowsGame2\Program.vb:line 9
InnerException:     

I cannot recall making any specific changes to the code that day, but to simply add abit more content. I know this is vague, but that's really all I can think of. I've been digging through every forum out there but to no avail. Is there any information that I can supply that might be helpful to understand the problem? I'm thankful for any help! /Christian

EDIT: I tried optimizing the code (and quite a bit), so it should run alot smoother once it does. For example, I now use a lot less excessive looping than before. The problem doesn't seem to be while running it though, but only when it start. Now I get it to start approx 1/5 times that i press debug.

Upvotes: 0

Views: 86

Answers (1)

Slubberdegullion
Slubberdegullion

Reputation: 159

It looks like the stack trace is pointing you to the Draw method. Make sure you aren't unnecessarily recreating objects every frame (either in draw or update), as this will happen 60 times a second (assuming 60fps).

Since you say it only happens some times, and other times it doesn't, also see if you can reduce what is being created at startup. Make sure you only create what you need when you need it.

If the stack trace is correct and the problem IS in your Draw method specifically, make sure you aren't needlessly recreating textures every frame, and ensure you call .Dispose() on any object that has it when you are done with it.

Upvotes: 0

Related Questions