[BUG] saveHeightmapToImage


08-06-2009 15:28:30

I found a bug in ET::saveHeightmapToImage. I'm using an older version (ETM 2.2, i think) so i don't know if this is corrected in newer versions.

When saving the heightmap to an Ogre::Image, you let Ogre free the memory allocated to the image buffer. The problem is that Ogre frees the memory using 'free'', but the buffer is created using 'new'. In Linux works fine, but in Windows the application crashes when the Ogre::Image object is deleted.

The reason for this is that there is no guarantee that 'new' will internally use 'malloc', or that 'delete' will internally use 'free'.
The memory allocation and deallocation have to follow the same rules. Failing to do so may cause unpredictable problems that may (or may not) make the application crash.

So, basically, you should replace the line 111:
uchar* data = new uchar[info.getWidth()*info.getHeight()*bpp];
by this one:
uchar* data = (uchar*)malloc(info.getWidth()*info.getHeight()*bpp*sizeof(uchar));

Hope this helps. :)


08-06-2009 21:13:44

I'm assuming you're using Ogre 1.6? Then yes, this is corrected in ETM v2.3.1.