Commit f3c037c1 authored by Janis Born's avatar Janis Born

add hotfix for memory error in loadTextureDataFromLodepng

parent bfad7296
......@@ -130,7 +130,7 @@ private:
// ========================================================================================================= \/
// ================================================================================================== FIELDS \/
// ========================================================================================================= \/
GLubyte* mData;
GLubyte* mData; // TODO: make this a std::unique_ptr to allow custom deleters
GLsizei mWidth;
GLsizei mHeight;
GLsizei mDepth;
......
......@@ -245,14 +245,20 @@ SharedTextureData loadTextureDataFromLodepng(const std::string &_filename, Color
}
// Decode the image
unsigned char* image;
errorCode = lodepng_decode_memory(&image, &width, &height, lodepngFile.mData, lodepngFile.mSize, colorType, bitdepth);
unsigned char* lodepngImage;
errorCode = lodepng_decode_memory(&lodepngImage, &width, &height, lodepngFile.mData, lodepngFile.mSize, colorType, bitdepth);
if(errorCode)
{
std::stringstream errorMsg;
errorMsg << "LodePNG error while decoding file " << _filename << " - " << errorCode << ": " << lodepng_error_text(errorCode);
throw std::runtime_error(errorMsg.str());
}
// HOTFIX: TextureData destroys its pointer using delete[], but lodepng uses malloc().
// As a hotfix, copy lodepngImage data to a memory location allocated using new[].
unsigned int dataSize = width * height * channels * bitdepth / 8;
unsigned char* image = new unsigned char[dataSize];
memcpy(image, lodepngImage, dataSize);
free(lodepngImage);
// LodePNG decodes 16 bit PNGs in big endian format ==> Convert
#ifndef ACGL_BIG_ENDIAN
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment