From 7179e408da8ecca80233ca954bcef0ef2a1eedda Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Feb 2018 12:34:01 -0800 Subject: [PATCH] GLES: Free localMemory later. It was still in use sometimes as of MapDevice(), so this is safer. --- ext/native/thin3d/GLRenderManager.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ext/native/thin3d/GLRenderManager.cpp b/ext/native/thin3d/GLRenderManager.cpp index 57a80d79ec..7c6bac029b 100644 --- a/ext/native/thin3d/GLRenderManager.cpp +++ b/ext/native/thin3d/GLRenderManager.cpp @@ -611,6 +611,14 @@ void GLPushBuffer::NextBuffer(size_t minSize) { void GLPushBuffer::Defragment() { if (buffers_.size() <= 1) { + // Let's take this chance to jetison localMemory we don't need. + for (auto &info : buffers_) { + if (info.deviceMemory) { + delete[] info.localMemory; + info.localMemory = nullptr; + } + } + return; } @@ -642,10 +650,7 @@ void GLPushBuffer::MapDevice() { // TODO: Can we use GL_WRITE_ONLY? info.deviceMemory = (uint8_t *)info.buffer->Map(GL_READ_WRITE, GL_MAP_WRITE_BIT); - if (info.deviceMemory) { - delete[] info.localMemory; - info.localMemory = nullptr; - } else if (!info.localMemory) { + if (!info.deviceMemory && !info.localMemory) { // Somehow it failed, let's dodge crashing. info.localMemory = new uint8_t[info.buffer->size_]; }