Menu

problem deleting TinyXML Node

Anonymous
2004-08-02
2004-08-03
  • Anonymous

    Anonymous - 2004-08-02

    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?

     
    • Yves Berquin

      Yves Berquin - 2004-08-02

      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

       
    • Anonymous

      Anonymous - 2004-08-03

      thanks alot!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.