Skip to content

Fix the issue where the Spine batch feature fails to work properly on native platforms. #18729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion native/cocos/2d/renderer/Batcher2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ CC_FORCE_INLINE void Batcher2d::handleMiddlewareDraw(RenderEntity* entity, Rende

// check for merge draw
auto enableBatch = !entity->getUseLocal();
if (enableBatch && _currTexture == texture && _currMeshBuffer == meshBuffer && !_currEntity->getUseLocal() && material->getHash() == _currMaterial->getHash() && drawInfo->getIndexOffset() == _currDrawInfo->getIndexOffset() + _currDrawInfo->getIbCount() && layer == _currLayer) {
if (enableBatch && _currTexture == texture && _currMeshBuffer == meshBuffer && !_currEntity->getUseLocal() && material->getHash() == _currMaterial->getHash() && drawInfo->getIndexOffset() == _currDrawInfo->getIndexOffset() + _currMiddlewareIbCount && layer == _currLayer) {
_currMiddlewareIbCount += drawInfo->getIbCount();
} else {
generateBatch(_currEntity, _currDrawInfo);
Expand Down
25 changes: 15 additions & 10 deletions native/cocos/editor-support/MiddlewareManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,22 @@ MeshBuffer *MiddlewareManager::getMeshBuffer(int format) {
}

void MiddlewareManager::updateOperateCache() {
for (auto &iter: _operateCacheMap) {
auto it = std::find(_updateList.begin(), _updateList.end(), iter.first);
if (iter.second) {
for (const auto &op : _operateCacheQueue) {
IMiddleware *editor = op.first;
bool isAddOperation = op.second;

auto it = std::find(_updateList.begin(), _updateList.end(), editor);
if (isAddOperation) {
if (it == _updateList.end()) {
_updateList.push_back(iter.first);
_updateList.push_back(editor);
}
} else {
if (it != _updateList.end()) {
_updateList.erase(it);
}
} else if (it != _updateList.end()) {
_updateList.erase(it);
}
}
_operateCacheMap.clear();
_operateCacheQueue.clear();
}

void MiddlewareManager::update(float dt) {
Expand All @@ -85,7 +90,7 @@ void MiddlewareManager::update(float dt) {
void MiddlewareManager::render(float dt) {
// Object._deferredDestroy is called after component update in Director.tick and before emitting BEFORE_DRAW event in which MiddlewareManager::render is invoked,
// so the native object may be released here and it needs to be erased from _updateList.
for (auto &iter : _operateCacheMap) {
for (auto &iter : _operateCacheQueue) {
auto it = std::find(_updateList.begin(), _updateList.end(), iter.first);
if (!iter.second && it != _updateList.end()) {
_updateList.erase(it);
Expand Down Expand Up @@ -126,11 +131,11 @@ void MiddlewareManager::render(float dt) {
}

void MiddlewareManager::addTimer(IMiddleware *editor) {
_operateCacheMap[editor] = true;
_operateCacheQueue.emplace_back(editor, true);
}

void MiddlewareManager::removeTimer(IMiddleware *editor) {
_operateCacheMap[editor] = false;
_operateCacheQueue.emplace_back(editor, false);
}

se_object_ptr MiddlewareManager::getVBTypedArray(int format, int bufferPos) {
Expand Down
3 changes: 2 additions & 1 deletion native/cocos/editor-support/MiddlewareManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class MiddlewareManager {
void updateOperateCache();

ccstd::vector<IMiddleware *> _updateList;
ccstd::unordered_map<IMiddleware *, bool> _operateCacheMap;
// bool true means add, false means delete
ccstd::vector<std::pair<IMiddleware *, bool>> _operateCacheQueue;
ccstd::unordered_map<int, MeshBuffer *> _mbMap;

SharedBufferManager _renderInfo;
Expand Down
Loading