From e1e452c0629ee74b527439b64681396c71afe4e1 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 5 Oct 2017 17:16:37 +0500 Subject: [PATCH] Draw manager: Avoid unneeded memory malloc/free when attempting to create missing uniform --- source/blender/draw/intern/draw_manager.c | 27 ++++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 7f600718dd1..05b8f1657c4 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -685,31 +685,32 @@ static DRWInterface *DRW_interface_duplicate(DRWInterface *interface_src) static void DRW_interface_uniform(DRWShadingGroup *shgroup, const char *name, DRWUniformType type, const void *value, int length, int arraysize) { - DRWUniform *uni = MEM_mallocN(sizeof(DRWUniform), "DRWUniform"); - + int location; if (type == DRW_UNIFORM_BLOCK) { - uni->location = GPU_shader_get_uniform_block(shgroup->shader, name); + location = GPU_shader_get_uniform_block(shgroup->shader, name); } else { - uni->location = GPU_shader_get_uniform(shgroup->shader, name); + location = GPU_shader_get_uniform(shgroup->shader, name); } - BLI_assert(arraysize > 0); - - uni->type = type; - uni->value = value; - uni->length = length; - uni->arraysize = arraysize; - - if (uni->location == -1) { + if (location == -1) { if (G.debug & G_DEBUG) fprintf(stderr, "Uniform '%s' not found!\n", name); /* Nice to enable eventually, for now eevee uses uniforms that might not exist. */ // BLI_assert(0); - MEM_freeN(uni); return; } + DRWUniform *uni = MEM_mallocN(sizeof(DRWUniform), "DRWUniform"); + + BLI_assert(arraysize > 0); + + uni->location = location; + uni->type = type; + uni->value = value; + uni->length = length; + uni->arraysize = arraysize; + BLI_addtail(&shgroup->interface->uniforms, uni); }