From e7fc8d98f5eb28d26d9a2a6be816dc5e57a1d678 Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Tue, 21 Jul 2015 15:41:57 +0200 Subject: [PATCH] Failure to alllocate vertex buffer would not fall back to vertex array properly. This should fix failure to use vertex arrays in OSX with high polycounts. Note this will not suffice as a fix when we move to VBOs exclusively (GL 3+), we'll have to think of some way to separate huge meshes to many VBOs. --- source/blender/gpu/intern/gpu_buffers.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 4920635f30b..4691659e04a 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -327,8 +327,10 @@ static GPUBuffer *gpu_buffer_alloc_intern(size_t size, bool use_VBO) gpu_buffer_pool_delete_last(pool); buf->pointer = MEM_mallocN(size, "GPUBuffer.pointer"); } - if (!buf->pointer) + if (!buf->pointer) { + MEM_freeN(buf); return NULL; + } } return buf; @@ -473,17 +475,17 @@ void GPU_drawobject_free(DerivedMesh *dm) static GPUBuffer *gpu_try_realloc(GPUBufferPool *pool, GPUBuffer *buffer, size_t size, bool use_VBOs) { - gpu_buffer_free_intern(buffer); - gpu_buffer_pool_delete_last(pool); - buffer = NULL; - /* try freeing an entry from the pool * and reallocating the buffer */ - if (pool->totbuf > 0) { + gpu_buffer_free_intern(buffer); + + buffer = NULL; + + while (pool->totbuf && !buffer) { gpu_buffer_pool_delete_last(pool); buffer = gpu_buffer_alloc_intern(size, use_VBOs); } - + return buffer; }