Merge pull request #15646 from Rypac/fix_quadcommand_crash

Fix crash due to reallocation of shared indices memory
This commit is contained in:
Ricardo Quesada 2016-05-24 11:29:28 -03:00
commit 23c5c18c91
2 changed files with 12 additions and 3 deletions

View File

@ -39,13 +39,18 @@ NS_CC_BEGIN
int QuadCommand::__indexCapacity = -1;
GLushort* QuadCommand::__indices = nullptr;
QuadCommand::QuadCommand()
: _indexSize(-1)
QuadCommand::QuadCommand():
_indexSize(-1),
_ownedIndices()
{
}
QuadCommand::~QuadCommand()
{
for (auto& indices : _ownedIndices)
{
CC_SAFE_DELETE_ARRAY(indices);
}
}
void QuadCommand::init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, const BlendFunc& blendType, V3F_C4B_T2F_Quad* quads, ssize_t quadCount,
@ -70,7 +75,8 @@ void QuadCommand::reIndex(int indicesCount)
if (indicesCount > __indexCapacity)
{
CCLOG("cocos2d: QuadCommand: resizing index size from [%d] to [%d]", __indexCapacity, indicesCount);
__indices = (GLushort*) realloc(__indices, indicesCount * sizeof(__indices[0]));
_ownedIndices.push_back(__indices);
__indices = new (std::nothrow) GLushort[indicesCount];
__indexCapacity = indicesCount;
}

View File

@ -25,6 +25,8 @@
#ifndef _CC_QUADCOMMAND_H_
#define _CC_QUADCOMMAND_H_
#include <vector>
#include "renderer/CCTrianglesCommand.h"
#include "renderer/CCGLProgramState.h"
@ -69,6 +71,7 @@ protected:
void reIndex(int indices);
int _indexSize;
std::vector<GLushort*> _ownedIndices;
// shared across all instances
static int __indexCapacity;