I'm chasing a bug for hours now. My program started to crash when i'm calling
Code: Select all
driver->addTexture(name, image);
Code: Select all
//! adds a surface, not loaded or created by the Irrlicht Engine
void CNullDriver::addTexture(video::ITexture* texture)
{
if (texture)
{
SSurface s;
s.Surface = texture;
texture->grab();
Textures.push_back(s);
// the new texture is now at the end of the texture list. when searching for
// the next new texture, the texture array will be sorted and the index of this texture
// will be changed. to let the order be more consistent to the user, sort
// the textures now already although this isn't necessary:
Textures.sort();
}
}
Code: Select all
//! Sorts an array with size 'size' using heapsort.
template<class T>
inline void heapsort(T* array_, s32 size)
{
// for heapsink we pretent this is not c++, where
// arrays start with index 0. So we decrease the array pointer,
// the maximum always +2 and the element always +1
T* virtualArray = array_ - 1;
s32 virtualSize = size + 2;
s32 i;
// build heap
for (i=((size-1)/2); i>=0; --i)
heapsink(virtualArray, i+1, virtualSize-1);
// sort array, leave out the last element (0)
for (i=size-1; i>0; --i)
{
T t = array_[0];
array_[0] = array_[i];
array_[i] = t;
heapsink(virtualArray, 1, i + 1);
}
}
Any thoughts? Where else could this bug come from? It seems that the < operator fails to compare the names in irrString.h, because one name has an invalid pointer inside.