Game Development Community

Torque X huge memory leak - Fixed

by Giuseppe De Francesco · in Torque X 2D · 03/18/2010 (11:54 am) · 298 replies

Well,

I'm not sure this is the right place to post this, maybe the blog? At any rate I'm posting here now.

Torque X has a huge memory leak, but seriously! I was working to a RPG game for a start so I didn't really notice, but 2 weeks ago I started YASS, a multiplayer side scrolling space shooter: a lot of particles, really a lot, and a lot of projectiles as well.

To let you understand here follows a short video of the game:



This is the memory situation after 3 minutes of gameplay (single player!!!) the game slowed down a lot:

forum.xnaitalia.com/download/leak1.png

So, I searched the forum and I realized that this issue is an old one and GG never got a grip on it (go figure why...) so I decided to fix the problems myself because I really need to publish YASS ;)

Long story short: I revised the whole engine and made a lot of fixes, some of them really of great importance, so here it is the situation playing my game (as you can see after 9 minutes the game still is 20% less than the original 3 minutes!):

forum.xnaitalia.com/download/leak2.png

There are still many stuff to fix, but at any rate in the current state I'm able to publish the game ;) I will make the SVN diff files available upon request (free of charge: pino AT dftgames DOT com).

Cheers,
Pino

About the author

In the software eng. field since 1981, in charge of R&D during last 10 years. IEEE Senior Member (and volunteer).

#161
04/07/2010 (9:21 pm)
I tried it with my game and didn't get a crash. Which is good because I went into review today. ;)

EDIT: Actually moved it over to playtest, to make certain I have no more issues.
#162
04/08/2010 (12:40 am)
The change you made to TorqueEngineComponent.cs causes an exception for me on Windows. Windows projects don't have access to Microsoft.Xna.Framework.GamerServices.

Change it to this to fix:
#if XBOX
                    return Game.IsActive && !Guide.IsVisible && !_exiting;
#else
                    return Game.IsActive && !_exiting;
#endif
#163
04/08/2010 (1:14 am)
@Henry: I couldn't get the Open/Close the Guide error either, but my daughter (which found it) could repro it each time... so I fixed it with her messing with the controller sat on my side :)

@William: actually windows does have access as well (if you don't box it), but you are right, I cannot assume that people will use LIVE in Windows as well. I'll correct that right away, thanks ;)
#164
04/08/2010 (1:59 pm)
What program are you guys using to track your game performance stats?
#165
04/08/2010 (2:26 pm)
I use CLR profiler for memory on Windows, and for CPU profiling I use NProf on windows. I use the Remote Performance Monitor for xbox (comes with xna game studio).

All of those are free. But, you can also get hold of better/more powerful tools if you spend some bucks, such as getting scitech's memory profiler for Windows .net apps. I haven't needed to go beyond the free profilers so far, but different people will prefer different app presentations and the paid for apps do tend to offer some useful extra features.
#166
04/08/2010 (4:33 pm)
@Duncan I have not been able to get the CLR profiler to work, I have tried and I get whatever game has stopped working, with torque games. I have tried the 64 and the x86. When I look at the console.log the only issue I see is torqueSettings.xml not found.

Oh well I wanted to try it out, I have the Ants profiler, but it gets pretty confusing. There are things in there that make no sense to me. However I am startingto understand some of the more esoteric parts of it.
#167
04/08/2010 (5:21 pm)
Heya,

Henry I have the same problem with CLR. It crashes with all torque games even the demos. Haven't tried it with the new engine.


Also on the engine front:
I'm getting a code 4 on the xbox with the following code in:

public bool IsActive
        {
            get
            {
                if (Game == null)
                    return false;
                else
#if XBOX
                    return Game.IsActive && !Guide.IsVisible && !_exiting;
#else
                    return Game.IsActive && !_exiting;
#endif
            }
        }

changing the code back to the original fixes the problem.

#168
04/08/2010 (6:10 pm)
I wouldn't recommend auto-disabling the engine when the guide is visible anyway. Multiplayer LIVE games are required not to pause when the guide is showing so if there is a problem then it ought to be fixed elsewhere, or the engine will only work for single player or local multiplayer games.

CLR profiler: I've never had a problem with it running torque games. My OS is XP Pro 32-bit running on a Dual Core Athlon.

@Henry: also check out scitech's memory profiler - it's cheaper than ANTS I think (I don't know if ANTS is better though as I haven't tried it).
#169
04/08/2010 (6:46 pm)
Hey Henry I've been using Scitech as per Duncan's suggestion and love it. They have a trial too.

As to the CLR:
I'm running Vista 64 (sad face) with a quad core Intel.
#170
04/11/2010 (7:04 pm)
Thanks to everyone for putting work in to this, especially Pino for organizing this. This is an amazing community effort! Now that I have SVN up and running on my machine I hope to be able to contribute. I'd like to build a common framework to help with the best practices found here: creators.xna.com/en-US/education/bestpractices31

@Pino: Can I get access to the patches? john (at) meistercreations.com
#171
04/12/2010 (10:45 am)
@Matthew and others...

The code 4 is because you haven't initiated a GamerServicesComponent (which you'll have to do in order to sell your game on Xbox LIVE).

In the Game.cs constructor add a GSC to the _myGame data member (which inherits from the XNA Framework's Game class).

I'm doing this from memory and this is raw XNA component management NOT TX component management. I think it looks something like this:

GamerServicesComponent gsc = new GamerServicesComponent();

_myGame.Components.Add(gsc);

_myGame.Run();

That should make the code 4 go away on the Xbox.

You might need to add:

using Microsoft.Xna.Framework.GamerServices;

Again...this is from memory...hopefully I'm not steering anyone too far off course.

--RB
#172
04/12/2010 (2:00 pm)
Hey Pino, Emailing right now for the diffs.

Best Regards,
#173
04/12/2010 (2:17 pm)
Hey guys,

I had a few hectic days (work... the one paying the mortgage!) so that added to releasing YASS made me quite absent. Starting tomorrow I'll be adding the asynchronous loader class to the core then I'll be right into TX3D.

Cheers,
Pino
#174
04/16/2010 (10:23 am)
Wow guys, just wow, I have been working for my mortgage as well, back on it, downloaded the latest builds. This is fantastic. Pino you have really rocked it.
#175
04/20/2010 (9:51 am)
Hey guys what happened to the Asynch loader thing? I was pretty interested in checking that out.
#176
04/20/2010 (10:06 am)
Hey Henry,

my fault: I've been super busy. I'm going to put that (and more I got from others) in these days. Sorry for the delay... mortgage needs to be paid :D
#177
04/20/2010 (11:28 pm)
Hey guys,

as you've seen in your email Duncan got writing permission on the repository so he published his work on the loader.

Thank you Duncan a lot!

Edit: You can get Duncan's Test Game here
#178
04/21/2010 (5:11 am)
I look forward to the first bug reports/feature requests on the async loading ;-)
#179
04/21/2010 (8:33 am)
Hey Pino,

Here's my license :)
and thank you again.
#180
04/21/2010 (9:33 am)
@Duncan...I don't have a bug to report...but have you shared any examples of how to use this feature to the best effect?

Thanks
--RB