From b8011150a5fbb2aec8c3c01173c1004246c7bc6c Mon Sep 17 00:00:00 2001 From: niu2x Date: Sat, 22 Jan 2022 23:16:07 +0800 Subject: [PATCH] bugfix: memory leak we should release old vertex buffer. --- cocos/renderer/backend/opengl/CommandBufferGL.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos/renderer/backend/opengl/CommandBufferGL.cpp b/cocos/renderer/backend/opengl/CommandBufferGL.cpp index e7ecfe05f9c4..f5065df5d02e 100644 --- a/cocos/renderer/backend/opengl/CommandBufferGL.cpp +++ b/cocos/renderer/backend/opengl/CommandBufferGL.cpp @@ -330,7 +330,7 @@ void CommandBufferGL::setWinding(Winding winding) void CommandBufferGL::setIndexBuffer(Buffer* buffer) { assert(buffer != nullptr); - if (buffer == nullptr) + if (buffer == nullptr || _indexBuffer == buffer) return; buffer->retain(); @@ -345,6 +345,7 @@ void CommandBufferGL::setVertexBuffer(Buffer* buffer) return; buffer->retain(); + CC_SAFE_RELEASE(_vertexBuffer); _vertexBuffer = static_cast(buffer); }