Removed the ArrayJanitors and refactored the Sax handlers

Discussion regarding the development of CEGUI itself - as opposed to questions about CEGUI usage that should be in the help forums.

Moderators: CEGUI MVP, CEGUI Team

User avatar
Blakharaz
Not too shy to talk
Not too shy to talk
Posts: 31
Joined: Wed Jan 12, 2005 12:06
Location: Potsdam, Germany
Contact:

Removed the ArrayJanitors and refactored the Sax handlers

Postby Blakharaz » Fri Jul 02, 2004 15:53

Hi, I tried to use CEGUI with Ogre and in Release compile had an "empty" exception thrown, I think it was because of a heap issue (like http://crayzedsgui.sourceforge.net/modu ... c&t=20).
The ArrayJanitors made the trouble, so I looked in the Xerces FAQ, they recommend to use XMLString::release instead of deleting a string (http://xml.apache.org/xerces-c/faq-build.html#faq-13), which the ArrayJanitors do in reset().

So I tried to replace the ArrayJanitors by ordinary char* and XMLCh* and stumbled upon some multiple code in the XML handlers like in

Code: Select all

if ((element == MappingElement) && !d_font->d_freetype)
{
   ArrayJanitor<XMLCh>   attr_name(XMLString::transcode(MappingImageAttribute));
   ArrayJanitor<char>  val_str(XMLString::transcode(attrs.getValue(attr_name.get())));
   String   image_name((utf8*)val_str.get());
   
   attr_name.reset(XMLString::transcode(MappingCodepointAttribute));
   utf32 codepoint = (utf32)XMLString::parseInt(attrs.getValue(attr_name.get()));
   ....
}
// handle root Font element
else if (element == FontElement)
{
   // get name of font we are creating
   ArrayJanitor<XMLCh>   attr_name(XMLString::transcode(FontNameAttribute));
   ArrayJanitor<char>  val_str(XMLString::transcode(attrs.getValue(attr_name.get())));
   String font_name = (utf8*)val_str.get();
   ...
}


All the code is about getting a value of an attribute of the current XML element, for this I wrote a helper class with only static methods. In there I uses XMLString::release instead of the ArrayJanitors.
There where a few other occurences of the ArrayJanitor in other files, I replaced them too and the exception vanished.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Removed the ArrayJanitors and refactored the Sax handlers

Postby CrazyEddie » Fri Jul 02, 2004 18:13

Cool. :)

If you submit a patch, I'll look it over and possibly make this change in CVS - anything that makes things clearer and less likely to crash is always welcome, especially as I'll be doing some more XML stuff very shortly ;)

User avatar
Blakharaz
Not too shy to talk
Not too shy to talk
Posts: 31
Joined: Wed Jan 12, 2005 12:06
Location: Potsdam, Germany
Contact:

Removed the ArrayJanitors and refactored the Sax handlers

Postby Blakharaz » Sun Jul 04, 2004 01:52

Okay, done. here it is

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Removed the ArrayJanitors and refactored the Sax handlers

Postby CrazyEddie » Sun Jul 04, 2004 09:33

Thanks :D

I've made a few more minor changes, mainly to fix memory leaks. Just doing some final testing, then I'll commit to CVS.

The code definately looks cleaner :)


Return to “CEGUI Library Development Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests