A minor bug

fatpwnage

15-07-2008 19:43:12

Here is the code at the bottom of MyGUI_Font.cpp:


Ogre::DataStreamPtr memStream( new Ogre::MemoryDataStream(imageData, data_size, true) );


Ogre::Image img;
img.loadRawData( memStream, finalWidth, finalHeight, Ogre::PF_BYTE_LA );


Ogre::Texture* tex = static_cast<Ogre::Texture*>(res);
// Call internal _loadImages, not loadImage since that's external and
// will determine load status etc again, and this is a manual loader inside load()
Ogre::ConstImagePtrList imagePtrs;
imagePtrs.push_back(&img);
tex->_loadImages( imagePtrs );

FT_Done_FreeType(ftLibrary);


The problem is that "true" is passed as the third argument to the Ogre::MemoryDataStream constructor. This tells the MemoryDataStream to call OGRE_FREE on imageData when it is destructed. However, imageData not allocated with malloc, it is allocated with new. So when OGRE_FREE is called it fails to deallocate the memory, which in the current Ogre SVN causes an assertion failure.

A simple fix would be to pass "false" instead of true and manually delete imageData. Fix shown below:


Ogre::DataStreamPtr memStream( new Ogre::MemoryDataStream(imageData, data_size, false) );


Ogre::Image img;
img.loadRawData( memStream, finalWidth, finalHeight, Ogre::PF_BYTE_LA );


Ogre::Texture* tex = static_cast<Ogre::Texture*>(res);
// Call internal _loadImages, not loadImage since that's external and
// will determine load status etc again, and this is a manual loader inside load()
Ogre::ConstImagePtrList imagePtrs;
imagePtrs.push_back(&img);
tex->_loadImages( imagePtrs );

delete imageData;

FT_Done_FreeType(ftLibrary);

Altren

16-07-2008 14:07:52

Ok, thanks, I applied your changes.