From 9c5581ba07f95567203f60f469dc919a895f34ef Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Mon, 6 Mar 2017 10:09:16 +0000 Subject: [PATCH] UPBGE: Fix buffer allocation in IMB_allocFromBuffer. In IMB_allocFromBuffer a copy of the image data is proceeded with a call to MEM_dupallocN. But all the MEM_ prefix functions work with memory allocated with the same function. This was not the case in Image::init, so the copy failed and the all the operations later used to mipmap were invalid and raise segmentation faults. To fix this issue we use MEM_mallocN in Image::init. Fix issue #411. --- source/gameengine/VideoTexture/ImageBase.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/gameengine/VideoTexture/ImageBase.cpp b/source/gameengine/VideoTexture/ImageBase.cpp index cfa37162f42e..e300b5a2347a 100644 --- a/source/gameengine/VideoTexture/ImageBase.cpp +++ b/source/gameengine/VideoTexture/ImageBase.cpp @@ -38,6 +38,8 @@ extern "C" { #include #include +#include "MEM_guardedalloc.h" + #include "EXP_PyObjectPlus.h" #include @@ -76,7 +78,7 @@ ImageBase::~ImageBase (void) { // release image if (m_image) - delete [] m_image; + MEM_freeN(m_image); } @@ -248,8 +250,8 @@ void ImageBase::init (short width, short height) m_imgSize = newSize; // release previous and create new buffer if (m_image) - delete [] m_image; - m_image = new unsigned int[m_imgSize]; + MEM_freeN(m_image); + m_image = (unsigned int *)MEM_mallocN(m_imgSize * sizeof(unsigned int), "ImageBase init"); } // new image size m_size[0] = width;