Fix the bug of trigger assertion in ValueArrayPool::get. (#12499)

This commit is contained in:
James Chen
2022-08-22 15:50:07 +08:00
committed by GitHub
parent a6e38dfa67
commit c65f3714d3
6 changed files with 41 additions and 26 deletions
@@ -26,6 +26,7 @@
#include "ValueArrayPool.h"
#include "base/Macros.h"
#include "base/memory/Memory.h"
#include "config.h"
namespace se {
@@ -41,14 +42,15 @@ ValueArrayPool::ValueArrayPool() {
}
}
ValueArray &ValueArrayPool::get(uint32_t argc) {
ValueArray &ValueArrayPool::get(uint32_t argc, bool &outNeedDelete) {
if (SE_UNLIKELY(_depth >= _pools.size())) {
auto *ptr = _pools.data();
_pools.resize(_depth + 1);
CC_ASSERT(_pools.data() == ptr);
initPool(_depth);
outNeedDelete = true;
auto *ret = ccnew ValueArray();
ret->resize(argc);
return *ret;
}
outNeedDelete = false;
CC_ASSERT(argc <= MAX_ARGS);
auto &ret = _pools[_depth][argc];
CC_ASSERT(ret.size() == argc);