Raycast, Delegates and Garbage

Topics: Developer Forum, User Forum
Jun 6, 2011 at 10:40 AM

Hi, I'm in the works of porting my code to the Xbox, and it's working fine. I've managed to clean a lot of garbage by profiling.

But I've noticed that the Raycast callback is generating some garbage. I researched a little, and I've found that a solution for the delegates' garbage is to use a static class, so I created a:

private static float RayCastOne(Fixture f, Vector2 p, Vector2 n, float fr)
And call it with World.Raycast(RayCastOne, point1, point2); But, it still generates garbage, so I think I'm missing something. Can anyone help me with this?

Developer
Jun 7, 2011 at 10:19 PM

Try ANTS Performance Profiler. They have a free demo to try it out. Should help narrow down your issues.

Jun 8, 2011 at 7:28 AM

Thanks Matt. I finally discovered what was causing garbage. Farseer still internally calls anonymous delegates when raycasting. After some research, as far as I understood when an anonymous delegate is called, a "copy" of the main class is created (in this case, a copy of the World class: in the profiler can be seen like something as "World.c__DisplayClass1"), which creates a little garbage.

Anyway, I managed to clean enough garbage to make my game to run at 60fps in the Xbox, so this is not a big issue anymore.