Permalink
Browse files

fix spine crush when render a huge mount of spine objects.

  • Loading branch information...
1 parent 46db86e commit cbf8e5163b5fd38dc76c71f1493db34e773cead5 u0u0 committed Sep 8, 2016
Showing with 4 additions and 43 deletions.
  1. +3 −33 cocos/editor-support/spine/SkeletonBatch.cpp
  2. +1 −10 cocos/editor-support/spine/SkeletonBatch.h
View
@@ -41,13 +41,8 @@ namespace spine {
static SkeletonBatch* instance = nullptr;
-void SkeletonBatch::setBufferSize (int vertexCount) {
- if (instance) delete instance;
- instance = new SkeletonBatch(vertexCount);
-}
-
SkeletonBatch* SkeletonBatch::getInstance () {
- if (!instance) instance = new SkeletonBatch(8192);
+ if (!instance) instance = new SkeletonBatch();
return instance;
}
@@ -58,10 +53,8 @@ void SkeletonBatch::destroyInstance () {
}
}
-SkeletonBatch::SkeletonBatch (int capacity) :
- _capacity(capacity), _position(0)
+SkeletonBatch::SkeletonBatch ()
{
- _buffer = new V3F_C4B_T2F[capacity];
_firstCommand = new Command();
_command = _firstCommand;
@@ -79,39 +72,16 @@ SkeletonBatch::~SkeletonBatch () {
delete command;
command = next;
}
-
- delete [] _buffer;
}
void SkeletonBatch::update (float delta) {
- _position = 0;
_command = _firstCommand;
}
void SkeletonBatch::addCommand (cocos2d::Renderer* renderer, float globalZOrder, GLuint textureID, GLProgramState* glProgramState,
BlendFunc blendFunc, const TrianglesCommand::Triangles& triangles, const Mat4& transform, uint32_t transformFlags
) {
- if (_position + triangles.vertCount > _capacity) {
- int newCapacity = std::max<int>(_capacity + _capacity / 2, _position + triangles.vertCount);
- V3F_C4B_T2F* newBuffer = new V3F_C4B_T2F[newCapacity];
- memcpy(newBuffer, _buffer, _position);
-
- int newPosition = 0;
- Command* command = _firstCommand;
- while (newPosition < _position) {
- command->triangles->verts = newBuffer + newPosition;
- newPosition += command->triangles->vertCount;
- command = command->next;
- }
-
- delete [] _buffer;
- _buffer = newBuffer;
- _capacity = newCapacity;
- }
-
- memcpy(_buffer + _position, triangles.verts, sizeof(V3F_C4B_T2F) * triangles.vertCount);
- _command->triangles->verts = _buffer + _position;
- _position += triangles.vertCount;
+ _command->triangles->verts = triangles.verts;
_command->triangles->vertCount = triangles.vertCount;
_command->triangles->indexCount = triangles.indexCount;
View
@@ -39,11 +39,6 @@ namespace spine {
class SkeletonBatch {
public:
- /* Sets the max number of vertices that can be drawn in a single frame. The buffer will grow automatically as needed, but
- * setting it to the appropriate is more efficient. Best to call before getInstance is called for the first time. Default is
- * 8192. */
- static void setBufferSize (int vertexCount);
-
static SkeletonBatch* getInstance ();
static void destroyInstance ();
@@ -54,13 +49,9 @@ class SkeletonBatch {
cocos2d::BlendFunc blendType, const cocos2d::TrianglesCommand:: Triangles& triangles, const cocos2d::Mat4& mv, uint32_t flags);
protected:
- SkeletonBatch (int capacity);
+ SkeletonBatch ();
virtual ~SkeletonBatch ();
- cocos2d::V3F_C4B_T2F* _buffer;
- int _capacity;
- int _position;
-
class Command {
public:
Command ();

0 comments on commit cbf8e51

Please sign in to comment.