[Bf-blender-cvs] [e1e452c0629] blender2.8: Draw manager: Avoid unneeded memory malloc/free when attempting to create missing uniform

Sergey Sharybin noreply at git.blender.org
Thu Oct 5 14:17:12 CEST 2017


Commit: e1e452c0629ee74b527439b64681396c71afe4e1
Author: Sergey Sharybin
Date:   Thu Oct 5 17:16:37 2017 +0500
Branches: blender2.8
https://developer.blender.org/rBe1e452c0629ee74b527439b64681396c71afe4e1

Draw manager: Avoid unneeded memory malloc/free when attempting to create missing uniform

===================================================================

M	source/blender/draw/intern/draw_manager.c

===================================================================

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);
 }



More information about the Bf-blender-cvs mailing list