From 38bf10baaabe4e89586d588b9a41e276748fe0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 4 Mar 2018 22:21:57 +0100 Subject: [PATCH] GL: Use AllocateAlignedMemory to make sure localMemory is always aligned. Fixes #10666 Seems the code that tries to align is faulty in some cases but this avoids the issue at least. --- ext/native/thin3d/GLRenderManager.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ext/native/thin3d/GLRenderManager.cpp b/ext/native/thin3d/GLRenderManager.cpp index 504bc9f2ca..62dbc1e60d 100644 --- a/ext/native/thin3d/GLRenderManager.cpp +++ b/ext/native/thin3d/GLRenderManager.cpp @@ -5,6 +5,7 @@ #include "thread/threadutil.h" #include "base/logging.h" #include "GPU/GPUState.h" +#include "Common/MemoryUtil.h" #if 0 // def _DEBUG #define VLOG ILOG @@ -592,7 +593,7 @@ void GLPushBuffer::Flush() { bool GLPushBuffer::AddBuffer() { BufInfo info; - info.localMemory = new uint8_t[size_]; + info.localMemory = (uint8_t *)AllocateAlignedMemory(size_, 16); info.buffer = render_->CreateBuffer(target_, size_, GL_DYNAMIC_DRAW); buf_ = buffers_.size(); buffers_.push_back(info); @@ -603,7 +604,7 @@ void GLPushBuffer::Destroy() { for (BufInfo &info : buffers_) { // This will automatically unmap device memory, if needed. render_->DeleteBuffer(info.buffer); - delete[] info.localMemory; + FreeAlignedMemory(info.localMemory); } buffers_.clear(); } @@ -637,7 +638,7 @@ void GLPushBuffer::Defragment() { // Let's take this chance to jetison localMemory we don't need. for (auto &info : buffers_) { if (info.deviceMemory) { - delete[] info.localMemory; + FreeAlignedMemory(info.localMemory); info.localMemory = nullptr; } } @@ -677,7 +678,7 @@ void GLPushBuffer::MapDevice() { if (!info.deviceMemory && !info.localMemory) { // Somehow it failed, let's dodge crashing. - info.localMemory = new uint8_t[info.buffer->size_]; + info.localMemory = (uint8_t *)AllocateAlignedMemory(info.buffer->size_, 16); mapChanged = true; }