You have this problem because you mix up the two paradigms to add nodes :
As soon as you make a LinkEndChild with an element, you are saying to TinyXML : use it, it's yours. You can't delete it after that : TinyXML already did, when it deleted configNode.
This is not the same with your configNode, because there you use InsertEndChild which request TinyXML to insert a COPY of the input structure. It's still your job to delete then.
Yves
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2004-08-03
thanks alot!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
bool MainWindow::SaveConfig( void )
{
TiXmlNode *configNode = NULL;
TiXmlNode *varNode = NULL;
TiXmlNode *DeclarationNode = NULL;
try
{
TiXmlDocument config;
configNode = new TiXmlElement( "CONFIG" );
varNode = new TiXmlElement( "VAR" );
// var lastmap
std::string MapFileName;
if( m_TileMaps.size() > m_CurrentMap )
{
MapFileName = m_TileMaps[ m_CurrentMap ].GetMapFileName();
}
varNode->ToElement()->SetAttribute( "lastmap", MapFileName.c_str() );//m_MapFileName );
configNode->LinkEndChild( varNode );
//
// finally add the config node
config.InsertEndChild( *configNode->ToElement() );
config.SaveFile( m_ConfgFileName );
delete configNode;
delete varNode; // crashes here
return true;
}
catch( ... )
{
delete configNode;
delete varNode;
return false;
}
}
Any Ideay why deleting varNode wouls cause a crash?
You have this problem because you mix up the two paradigms to add nodes :
As soon as you make a LinkEndChild with an element, you are saying to TinyXML : use it, it's yours. You can't delete it after that : TinyXML already did, when it deleted configNode.
This is not the same with your configNode, because there you use InsertEndChild which request TinyXML to insert a COPY of the input structure. It's still your job to delete then.
Yves
thanks alot!