cocos-engine icon indicating copy to clipboard operation
cocos-engine copied to clipboard

SharedBuffer, MeshBuffer, TypeArrayPool are trying to add init hook after restart

Open timlyeee opened this issue 3 years ago • 0 comments

Cocos Creator version

3.6

System information

Native platform

Issue description

void MeshBuffer::afterCleanupHandle() {
    clear();
    se::ScriptEngine::getInstance()->addAfterInitHook([this] { init(); });
}
void MeshBuffer::init() {
    auto *rIB = new IOTypedArray(se::Object::TypedArrayType::UINT16, _ib.getCapacity());
    _ibArr.push_back(rIB);

    auto *rVB = new IOTypedArray(se::Object::TypedArrayType::FLOAT32, _vb.getCapacity());
    _vbArr.push_back(rVB);

    se::ScriptEngine::getInstance()->addAfterCleanupHook([this] { afterCleanupHandle(); });
}

Before 3.6 ScriptEngine won't clean all init hooks, so it will add infinite InitHook for itself. The behavior is good as no bug is produced.

After 3.6, each time ScriptEngine restart, it will clean up the init hook, which makes the logic meaningless.

Same thing in Shared Buffer, TypeArrayPool.

Relevant error log output

No response

Steps to reproduce

Just reviewing the codes

Minimal reproduction project

No response

timlyeee avatar Aug 02 '22 03:08 timlyeee