From d493654f8055c1314cb633026b1c84835b89473d Mon Sep 17 00:00:00 2001 From: Dwyer Date: Wed, 11 Aug 2021 15:10:51 +0800 Subject: [PATCH 1/2] fix crash when create too many spine animations at a time cause a crash for memory alloc failed Creating a large number of different spine animations at the same time results in the allocation of vertex vector(large than 1.4 billion) Then run out of memory and crash. --- cocos/editor-support/spine/v4/SkeletonBatch.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cocos/editor-support/spine/v4/SkeletonBatch.cpp b/cocos/editor-support/spine/v4/SkeletonBatch.cpp index 36e338c4b44f..0282c4a9e7cf 100644 --- a/cocos/editor-support/spine/v4/SkeletonBatch.cpp +++ b/cocos/editor-support/spine/v4/SkeletonBatch.cpp @@ -103,6 +103,17 @@ void SkeletonBatch::update (float delta) { cocos2d::V3F_C4B_T2F* SkeletonBatch::allocateVertices(uint32_t numVertices) { if (_vertices.size() - _numVertices < numVertices) { + //Creating a large number of different spine animations at the same time + //results in the allocation of vertex vector(large than 1.4 billion) + //Then run out of memory and crash. + if (_vertices.size() > VETEXT_BUFF_SIZE) + { + //CCLOG("SkeletonBatch::allocateVertices _vertices size:%d, clear here...", _vertices.size()); + reset(); + _vertices.resize(VETEXT_BUFF_SIZE); + } + //CCLOG("SkeletonBatch::allocateVertices _vertices vector size:%d, _numVertices:%d, add vertics:%d", _vertices.size(), _numVertices, numVertices); + cocos2d::V3F_C4B_T2F* oldData = _vertices.data(); _vertices.resize((_vertices.size() + numVertices) * 2 + 1); cocos2d::V3F_C4B_T2F* newData = _vertices.data(); From 4a249ec0a89e8dea6f16a2b719dcd132971b22b0 Mon Sep 17 00:00:00 2001 From: Dwyer Date: Wed, 11 Aug 2021 15:13:32 +0800 Subject: [PATCH 2/2] Update SkeletonBatch.cpp --- cocos/editor-support/spine/v4/SkeletonBatch.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/editor-support/spine/v4/SkeletonBatch.cpp b/cocos/editor-support/spine/v4/SkeletonBatch.cpp index 0282c4a9e7cf..f0f8141d352b 100644 --- a/cocos/editor-support/spine/v4/SkeletonBatch.cpp +++ b/cocos/editor-support/spine/v4/SkeletonBatch.cpp @@ -37,6 +37,7 @@ USING_NS_CC; #define EVENT_AFTER_DRAW_RESET_POSITION "director_after_draw" using std::max; #define INITIAL_SIZE (10000) +#define VETEXT_BUFF_SIZE (64000) #include "renderer/ccShaders.h" #include "renderer/backend/Device.h"