• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Mybowlcut

TinyXML++ memory leaks

10 posts in this topic

Hey. Visual Leak Detector is telling me that I've got memory leaks coming from code that uses ticpp (TinyXML++) code:
void CGE_Level::Write_Tiles(ticpp::Element* root) const
{
	using namespace ticpp;

	Element* tiles = new Element("tiles");
	Element* tile = NULL;
	root->LinkEndChild(tiles);
	for(const_tile_it it = this->tiles.begin(); it != this->tiles.end(); ++it)
	{ // Write each background tile.
		tile = new Element("tile");
		tile->SetAttribute("type", it->Type());
		tile->SetAttribute("pass", it->Passability());
		tiles->LinkEndChild(tile);
	}
}

void CGE_Level::Write_Portals(ticpp::Element* root) const
{
	using namespace ticpp;
	
	Element* portals = new Element("portals");
	Element* portal = NULL;
	root->LinkEndChild(portals);
	for(const_portal_it it = this->portals.begin(); it != this->portals.end(); ++it)
	{ // Write each background tile.
		portal = new Element("portal");
		portal->SetAttribute("to_level", it->To_Level());
		portal->SetAttribute("from_x", it->From_Pos().y);
		portal->SetAttribute("from_y", it->From_Pos().y);
		portal->SetAttribute("to_x", it->To_Pos().x);
		portal->SetAttribute("to_y", it->To_Pos().y);
		portals->LinkEndChild(portal);
	}
}

void CGE_Level::Write(const std::string& file_name) const
{
	using namespace ticpp;

	Document xml_doc(file_name);

	Declaration* dec = new Declaration(DEF_VER, DEF_ENC, DEF_STA);
	xml_doc.LinkEndChild(dec);

	Element* root = new Element("level");
	xml_doc.LinkEndChild(root);
	root->SetAttribute("width", size.x);
	root->SetAttribute("height", size.y);

	Write_Tiles(root);
	Write_Portals(root);

	xml_doc.SaveFile(file_name);
}
Quote:
WARNING: Visual Leak Detector detected memory leaks! ---------- Block 4309 at 0x0051CC78: 8 bytes ---------- Call Stack: c:\tinyxml++\ticpp.cpp (1089): TiCppRC::TiCppRC c:\tinyxml++\tinyxml.h (217): TiXmlBase::TiXmlBase c:\tinyxml++\tinyxml.cpp (136): TiXmlNode::TiXmlNode c:\tinyxml++\tinyxml.cpp (508): TiXmlElement::TiXmlElement c:\tinyxml++\ticpp.cpp (874): ticpp::Element::Element c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (103): CGE_Level::Write_Portals c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (135): CGE_Level::Write c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (145): CGE_Editor::Save c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (56): CGE_Editor::Update_And_Draw c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (46): CGE_Editor::Run c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\main.cpp (72): main f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (586): __tmainCRTStartup f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): mainCRTStartup 0x7C817067 (File and line number not available): RegisterWaitForInputIdle Data: 01 00 00 00 00 00 00 00 ........ ........ ---------- Block 4307 at 0x0051CB20: 12 bytes ---------- Call Stack: c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (103): CGE_Level::Write_Portals c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (135): CGE_Level::Write c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (145): CGE_Editor::Save c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (56): CGE_Editor::Update_And_Draw c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (46): CGE_Editor::Run c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\main.cpp (72): main f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (586): __tmainCRTStartup f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): mainCRTStartup 0x7C817067 (File and line number not available): RegisterWaitForInputIdle Data: 0C B0 4C 00 78 CC 51 00 68 CB 51 00 ..L.x.Q. h.Q..... ---------- Block 4291 at 0x0051C820: 8 bytes ---------- Call Stack: c:\tinyxml++\ticpp.cpp (1089): TiCppRC::TiCppRC c:\tinyxml++\tinyxml.h (217): TiXmlBase::TiXmlBase c:\tinyxml++\tinyxml.cpp (136): TiXmlNode::TiXmlNode c:\tinyxml++\tinyxml.cpp (508): TiXmlElement::TiXmlElement c:\tinyxml++\ticpp.cpp (874): ticpp::Element::Element c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (92): CGE_Level::Write_Tiles c:\documents and settings\bill\my documents\visual studio 2005\projects\console_game_engine\console_game_engine\cge_level.cpp (133): CGE_Level::Write c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (145): CGE_Editor::Save c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (56): CGE_Editor::Update_And_Draw c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\cge_editor.cpp (46): CGE_Editor::Run c:\documents and settings\bill\my documents\visual studio 2005\projects\console_level_editor\console_level_editor\main.cpp (72): main f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (586): __tmainCRTStartup f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): mainCRTStartup 0x7C817067 (File and line number not available): RegisterWaitForInputIdle Data: 01 00 00 00 00 00 00 00 ........ ........ ETC...
In total there are 208! I didn't delete the pointers I created here because I followed the tutorial and they didn't use delete. I read somewhere that TinyXML++ handles the memory internally... but when I saw vld reporting the memory leaks, I realised I had stuffed up and that I hadn't actually deleted the pointers... pretty stupid I know. So two questions: 1) What does TinyXML++ do in terms of handling new'd memory? 2) Why would they not delete the pointers in their tutorials? Cheers!
0

Share this post


Link to post
Share on other sites
It looks more likely to me that your leak detector is wrong. Once you link a node into an XML document it would be foolish to expect you to have to delete it manually. But I've not looked at the code myself.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Kylotan
It looks more likely to me that your leak detector is wrong. Once you link a node into an XML document it would be foolish to expect you to have to delete it manually. But I've not looked at the code myself.
Hmm.. well I deleted the pointers after each new and the leaks went away... I still am curious about it all though.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Kylotan
It looks more likely to me that your leak detector is wrong. Once you link a node into an XML document it would be foolish to expect you to have to delete it manually. But I've not looked at the code myself.
On the other hand, it seems silly that the XML document must be allocated in such a way that the standard single-object no-parameter delete will properly deallocate them. Perhaps there are additional optional arguments, one of which is a deallocator instance, but somehow I doubt it.
0

Share this post


Link to post
Share on other sites
Gah! We've been using TinyXML at work and haven't been deleting any of the allocated memory. We were under the assumption that when the document went out of scope, it would automatically delete any linked nodes.

But on the third hand, it is possible for you to link a node object that's on the stack, in which case deleting it would crash. In that case, the usage guide in the documentation just plain sucks for not making any of this clearer :)
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
Quote:
Original post by Kylotan
It looks more likely to me that your leak detector is wrong. Once you link a node into an XML document it would be foolish to expect you to have to delete it manually. But I've not looked at the code myself.
On the other hand, it seems silly that the XML document must be allocated in such a way that the standard single-object no-parameter delete will properly deallocate them.

Why? The semantics of TinyXML clearly imply that (a) it owns the document tree, and (b) you pass in nodes that you allocate. I can see no good argument for it not simply using the delete operator on everything linked into it.

EDIT: In fact, given that TinyXML (or at least the copy I have here) clearly has
while ( node ) { temp = node; node = node->next; delete temp; }
in the TiXMLNode destructor, I'm guessing this is just a bug in the TinyXML++ wrapper.

[Edited by - Kylotan on December 17, 2008 5:12:29 AM]
0

Share this post


Link to post
Share on other sites
My theory is that the TinyXML++ wrapper has a bug, because I don't think you should be freeing anything that you have linked into the document.
0

Share this post


Link to post
Share on other sites
By looking at the bugtracker ( http://code.google.com/p/ticpp/issues/detail?id=17&can=1&q=memory ) it seems a memory leak was fixed in revision 93.

But if there are more leaks, I really need to find out how to work around them, before we ship the software I'm currently working on.

On which version of ticpp are you seeing the problem?

- michael
0

Share this post


Link to post
Share on other sites
I updated my version to revision r98 from ticpp svn (see http://code.google.com/p/ticpp/source/checkout ).

Valgrind on Linux does not show any leaks using this version.

- michael
0

Share this post


Link to post
Share on other sites
How did you compile your tinyxml project?
I've been working on a smaller (and simpler) version of Visual Leak Detector (mostly for learning purposes) and while I did this I noticed that if I create a project as a static library and link it with another executable, the overwritten new and delete functions of my leak detector were called in a wrong way (delete[] in a module in the static lib was redirected to delete (without [] brackets) in my leak detector) or not at all. This behaviour vanished when I linked the leak detector against the static library as well as against the executable.

If you've compiled tinyxml as a dll, then you need to link visual leak detector to that one as well (or it won't be able to detect the deallocation of the 'Element'), although you propably already know that.

As far as I know, the leak detector works in a similar way (overwriding operator new, and so on) and I assume it could suffer from the same problems as mine did.

Hope that helps :)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0