Stunt Playground source and TinyXml memory issue

greyWiz

04-06-2006 18:05:53

Hi, first of all, I'd like to thank walaber A LOT for his initiative on releasing Stunt Playground source code - it's proving very, very useful and time saving! 8)

However, I'm having a little problem with merging it inside my code. I already have a XML-based scene loader assembled, and I was trying just to include the Car class and the loadRigidBody function inside my scene (I removed the sound manager, the replay classes and all the other stuff that wasn't related to the loading of the car's hierarchy and mesh). It worked once but now, without any visible explanation, it just stopped working...

The debugger catches an exception related to the deletion of some kind of array inside the TiXmlDocument::Parse method. Curiously enough, the point where it happens there's nothing to do with the Car class, but it crashes when I insert Car's source code into my project.

Here's the beginning of my code:
try
{
DataStreamPtr pStream = ResourceGroupManager::getSingleton().
openResource( sceneName, groupName );

String data = pStream->getAsString();
// Open the .scene File
mXMLDoc = new TiXmlDocument();
mXMLDoc->Parse( data.c_str() ); // ERROR!!!
pStream->close();
pStream.setNull();
//...

It's the beginning of my scene loader; I checked the String data, and it's getting the file correctly.

I already tried
#include <OgreNoMemoryMacros.h>
#include "tinyxml.h"
#include <OgreMemoryMacros.h>

in every place where I include the tinyxml.h header, but to no use. I also tried the following:
#include <OgreNoMemoryMacros.h>
mXMLDoc = new TiXmlDocument();
mXMLDoc->Parse( data.c_str() );
#include <OgreMemoryMacros.h>

But, once again, nothing happened.

The exception takes me to the OgreMemoryManager class, inside the overloaded delete[] operator. I really don't know what's happening, I already tried to trace the TiXmlDocument::Parse() steps, but I couldn't take any conclusions. I already made a quick search on Ogre's forum looking for incompatibilities with TinyXml, but I didn't find anything that could solve my problem. Any hint about what could be happening will be very, very, very appreciated. :D

Thanks in advance!
Edgard

PS: as I'm just inserting the loadRigidBody function without major modifications, I have two TiXmlDocument instances created inside my code (managing different files), one from my scene loader and the other from loadRigidBody(). Could it cause any kind of problem?

walaber

04-06-2006 20:28:55

i don't think so... are you sure there are no errors in the XML files? you can sometimes get strange crashes when, for example, you try to access an "Attribute()" on a node, that dowsn't exist with TinyXML...

greyWiz

05-06-2006 04:51:49

... I was wondering... Both the .car and the .rb files are loaded in the stack... Could it be some kind of stack overflow?

greyWiz

09-06-2006 13:37:38

@walaber: I changed the code to allocate TiXmlDocument instances in the heap instead of the stack and the problems disappeared. Seems like it was really a stack overflow.

Once again, thanks for your initiative! :D
Edgard