Page 1 of 1

Releasing Memory?

Posted: 30.06.2003, 00:29
by jjszucs
[WARNING: Possible newbie developer question ahead.]

I am working on my own front-end to Celestia, using the engine and other libraries, but replacing the UI with one of my own design. I am having problems with memory leaks: none of the stars and other Celestia objects are apparently being freed in my code. I would like to know how I should be releasing the Celestia objects.

This is on the Windows platform with Visual C++ .NET (original, not yet upgraded to ViC++.NET 2003). Following devguide.text and the example of the existing Celestia front-end code, I:
1) Create a new Universe.
2) Load the star names with a call to StarNameDatabase::readNames().
3) Load the stars with a call to StarDatabase::loadBinary().
4) Call StarDatabase::finish().
5) Call Stars::setNameDatabase() with the StarNameDatabase from step 1.
6) Call Universe::setStarCatalog().
7) Call LoadSolarSystemObjects() to load the solar system.

During my application's clean-up sequence, I delete the resulting objects in the following order:
1) SolarSystemCatalog
2) StarDatabase
3) StarNameDatabase
4) Universe

Executing just the above sequence (load and immediately clean-up, no rendering or anything), the VC++ debug run-time reports literally thousands of memory leaks. If I don't load any Celestia objects, I have no leaks. What is the correct procedure for releasing the loaded Celestia objects?

Thanks in advance!

Posted: 30.06.2003, 03:51
by marc
I stumbled upon the same problem. Each time I re-load the star database with the MySQL addon there is a large memory leak that is proportional to the number of stars being unloaded.
I found the //TODO: Clean up! comments in the code, but didn't look much further into the problem. For my game, like Celestia, I only plan to load the star db once during startup.

Posted: 30.06.2003, 05:16
by chris
Yes, there are probably memory leaks in Celestia :oops:

I confess that I have not been too careful about cleaning up objects who's lifetime is an entire Celestia session. But my assumptions about object lifetime obviously don't necessary hold if you're building your own app based on Celestia code . . . I'll work on tidying this up. If like Celestia your app just loads all the objects at startup and keeps them around until the program is done running, it should be safe to ignore the warnings. Otherwise, you might want to take a look at the destructors for SolarSystem, StarDatabase, and Universe. The parser may have some memory leaks as well . . . no excuse here except for sloppy programming on my part.

--Chris

Posted: 01.07.2003, 01:52
by jjszucs
Chris and Marc:

Thanks for your replies. I'm brand-new to Celestia and really just wanted to see if I was doing anything stupid to cause the leaks.

As in Celestia, the lifetimes of the objects span the entire session, so this is not a major problem. It is really only an annoyance during development, where the debugger sits there and spews leak warnings after I exit the application, until I lose my patience and select Debug | Stop Debugging :wink:.

At some point, I may take a crack at fixing the leaks in the areas that Chris suggested. Thanks again!

-- John

Posted: 02.07.2003, 10:29
by Paolo
jjszucs Wrote:
I am working on my own front-end to Celestia, using the engine and other libraries, but replacing the UI with one of my own design.


jjszucs please forgive my questions but I'm a little bit curious:
Have you planned to prepare a multiplatform UI? Have you red the thread in Users Forum http://ennui.shatters.net/forum/viewtopic.php?t=2649&start=10 and seen my feature request pages in my website?

Have you planned to merge your project with Celestia development team in a future?

Bye- Paolo

Posted: 09.07.2003, 03:28
by Guest
Please forgive my questions but I'm a little bit curious...

Sorry for the delayed response (been busy over the past few days).

I suppose I can elaborate a little on what I'm up to.

For several years now, I have been toying with the idea of creating a real-time strategy/management game of space exploration. Some of you may remember Buzz Aldrin's Race into Space (BARIS). Think about that, but with more sophisticated gameplay and a modern 3D graphics and UI presentation, and some elements of the Railroad Tycoon, SimCity, and Civilization series and Rise of Nations added to the mix.

The player would lead a national or international space agency (for example, NASA or the ESA) and do things like:
1) Build spacecraft, selecting from various historical and hypothetical/concept designs (for example, Mercury/Atlas, Gemini/Titan, Apollo/Saturn, Space Shuttle, Delta Clipper, VentureStar, Mars Direct, etc.)
2) Build support facilities on the ground, such as launch complexes, landing strips, etc.
3) Plan space missions using a simple series of steps, such as ascent, orbital maneuvering, transfer orbits, rendezvous, docking, descent, and landing to build a simplified mission profile.
4) Research technologies in various areas, such as propulsion, structures, guidance, navigation, and control, communications, and life support to "unlock" new types of spacecraft and other units.
5) (Maybe) recruit, select, and train crew members and assign them to missions.

As in BARIS, the player would compete with AI's (or possibly human players over the Internet) running other space agencies to achieve milestones like the first artificial satellite or the first human landing on the Moon. But it would be fairly open-ended too, like SimCity. As long as you can keep the cash flowing, you could pretty much do whatever you wanted to. The game would be realistic enough to capture the essence of space exploration, but simple enough to be played by a reasonably sophisticated gamer.

When I discovered Celestia, this idea resurfaced in my mind. It seems to address most of the graphics and simulation engine requirements, allowing me to concentrate on the game design itself. Some of the ideas would obviously require some changes to the engine, but it's far better than starting from scratch.

Bear in mind that I am just toying with this idea at this point. I am a professional software developer, but I have no prior professional experience in game development. I have a full-time (+) job and limited time/resources, and thus a track record of several false starts on this and other game ideas.

Have you planned to prepare a multiplatform UI? Have you read the thread in Users Forum http://ennui.celestiaproject.net/forum/viewtop ... 9&start=10

Not at this point. I'm currently working on Windows only. However, if the project did take off and someone wanted to do a Linux (or MacOS X) port, I would lean toward a relatively thin platform-dependent UI layer that "skinned" the platform's native UI, with most of the UI flow and behavior implemented by a cross-platform UI process layer. This is similar to the design of the Celestia application itself - a Windows- (or Linux-) specific layer calls a portable CelestiaCore, which in turn calls into the engine.

If there already is a multi-platform UI library suitable for games out there, I'd consider using that. But, as some other posters suggested, in the thread that you referenced, such a library is basically a project in itself.

[Have you] seen my feature request pages in my website?

Yes. I've dropped you an E-mail subscribing to several of the feature requests that would be relevant to this idea.

Have you planned to merge your project with Celestia development team in the future?


Any changes that I would make to the engine would have a generalized design and I would contribute them back to the main Celestia code base.

If project actually turns into something, I would release it under GPL as required by the Celestia engine's GPL license. But I think the game should be separate from the main Celestia code base. Fortunately, the design of the Celestia engine readily supports this. A game like this would just be another front-end to the Celestia engine, replacing the main Celestia executable.

-- John

Posted: 09.07.2003, 10:09
by marc
Sounds like a great project John good luck with it.

Plib http://plib.sourceforge.net/ has a bunch of OpenGL GUI components called PUI which im looking at using in my own celestia based game project.
I havn't written any code with PUI yet but you might find it useful.

I have made some progress using the embedded MySQL library with which I'm going to use for all the data management. (See my addon below). You might find that useful too.