Skip to content

Commit

Permalink
UPBGE: Fix buffer allocation in IMB_allocFromBuffer.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
panzergame committed Mar 6, 2017
1 parent e1b5a9b commit 9c5581b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/gameengine/VideoTexture/ImageBase.cpp
Expand Up @@ -38,6 +38,8 @@ extern "C" {
#include <vector>
#include <string.h>

#include "MEM_guardedalloc.h"

#include "EXP_PyObjectPlus.h"
#include <structmember.h>

Expand Down Expand Up @@ -76,7 +78,7 @@ ImageBase::~ImageBase (void)
{
// release image
if (m_image)
delete [] m_image;
MEM_freeN(m_image);
}


Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9c5581b

Please sign in to comment.