gl_engine: Fix memory leak in the IndexBuffer object

The CPU buffer cache in the IndexBuffer object needs to be cleared, otherwise it will cause memory leaks and reduce performance per frame
This commit is contained in:
RuiwenTang 2024-11-08 15:47:45 +08:00 committed by Hermet Park
parent 8b37ec5d9c
commit 159bf6949e
3 changed files with 14 additions and 6 deletions

View file

@ -117,9 +117,13 @@ uint32_t GlStageBuffer::pushIndex(void *data, uint32_t size)
return offset;
}
void GlStageBuffer::flushToGPU()
bool GlStageBuffer::flushToGPU()
{
if (mStageBuffer.empty()) return;
if (mStageBuffer.empty() || mIndexBuffer.empty()) {
mStageBuffer.clear();
mIndexBuffer.clear();
return false;
}
mGpuBuffer.bind(GlGpuBuffer::Target::ARRAY_BUFFER);
@ -131,6 +135,9 @@ void GlStageBuffer::flushToGPU()
mGpuIndexBuffer.unbind(GlGpuBuffer::Target::ELEMENT_ARRAY_BUFFER);
mStageBuffer.clear();
mIndexBuffer.clear();
return true;
}
void GlStageBuffer::bind()

View file

@ -56,7 +56,7 @@ public:
uint32_t pushIndex(void* data, uint32_t size);
void flushToGPU();
bool flushToGPU();
void bind();

View file

@ -953,10 +953,11 @@ bool GlRenderer::sync()
task->setTargetViewport(RenderRegion{0, 0, static_cast<int32_t>(surface.w), static_cast<int32_t>(surface.h)});
mGpuBuffer->flushToGPU();
if (mGpuBuffer->flushToGPU()) {
mGpuBuffer->bind();
task->run();
}
mGpuBuffer->unbind();