This project has moved and is read-only. For the latest updates, please go here.

Farseer crashing xbox due to not removing stuff correctly(?)

Topics: User Forum
May 5, 2008 at 3:36 PM
Ok, first off thanks for this great engine. We've been using it for around eight weeks now to build a simple physics-based top-down space-ish shooter. Now I'm debugging it to run on xbox and I'm having trouble with garbage collecting. Or so I think.

Ship(s) shoot stuff with bodies and geometry. There are two kinds of stuff, but it doesn't seem to matter.
All stuff is put in to a list<Stuff> stuff.
All stuff have a logic that tells us when they should be removed. Working as supposed thus far.

I have a cool predicate, so I can do stuff.RemoveAll(coolPred);
This clutters everything up rather quickly, so I'm also using that predicate to populate another list to foreach and call Dispose() on all bodies an geometry. Everything seems to work fine on my PC, but the Xbox just crashes after a certain number of stuff has been released. Limit seems to be around a few hundred particles. So if the limit was 200, I could shoot 199 bullets and be happy with it, till I shoot one more and boom.

So it sounds like my stuff is cluttering up somehow. Are there more advanced (or basic:D) garbage collection practices I could use? Any help is really appreciated.

Fun fact: the game should be ready to demo before the weekend. I hope to get it up here with our ugly sources!
May 5, 2008 at 5:38 PM
Edited May 5, 2008 at 5:40 PM
You may have to dig thru the XNA forums looking for info on Garbage Collection on the XBox. One thing I recall was that Predicates don't work as well on XBox because they create garbage.

You may also want to avoid For--Each calls as I think they have the same problem. Better to use For..Next.

Look in the Farseer source code to see how it traverses lists. I did some optimization a while back so it should be a good sample of how to do it.
May 5, 2008 at 9:32 PM
What sort of error are you getting. There are some excellent performance tips for the Xbox CLR at While generics and delegates are simple and elegant to use, they are probably not the best choice for a game. It is likely far more efficient to do an old fashioned for loop. There is another nice talk concerning 2D graphics performance, which could also be an issue, depending on what your error is
May 5, 2008 at 11:40 PM
Hey thanks for the tips, I'll study what I can and report anything useful. And here I was thinking that optimizing code like this would be left for more hardcore projects:D