[Bf-blender-cvs] [930d0070b6f] master: Fix T61956: Errors when instancing grease pencil objects

Antonioya noreply at git.blender.org
Tue Feb 26 20:29:00 CET 2019


Commit: 930d0070b6fd337fc059ea9e486e598831ed28ab
Author: Antonioya
Date:   Tue Feb 26 20:28:06 2019 +0100
Branches: master
https://developer.blender.org/rB930d0070b6fd337fc059ea9e486e598831ed28ab

Fix T61956: Errors when instancing grease pencil objects

The problem was not only for instances, but for particles too, and produced segment fault.

For some reason due any internal modification of how duplicated objects are generated, the duplicated object are not available when the draw manager try to use runtime data.

Now, before drawing the particle or the instance, the pointers of the duplicated objects are reassigned to the original "real object" to get full access to runtime data.

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

M	source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index c18aa27ea79..ab75299ca1e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -68,6 +68,8 @@ tGPencilObjectCache *gpencil_object_cache_add(
 
 	cache_elem->ob = ob;
 	cache_elem->gpd = (bGPdata *)ob->data;
+	strcpy(cache_elem->name, ob->id.name);
+
 	copy_v3_v3(cache_elem->loc, ob->obmat[3]);
 	copy_m4_m4(cache_elem->obmat, ob->obmat);
 	cache_elem->idx = *gp_cache_used;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index fa4aa3a4c14..b062094de30 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -639,6 +639,30 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
 void GPENCIL_cache_finish(void *vedata)
 {
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+	tGPencilObjectCache *cache_ob = NULL;
+	Object *ob = NULL;
+
+	GHash *gh_objects = BLI_ghash_str_new(__func__);
+	/* create hash of real object (non duplicated) */
+	for (int i = 0; i < stl->g_data->gp_cache_used; i++) {
+		cache_ob = &stl->g_data->gp_object_cache[i];
+		if (!cache_ob->is_dup_ob) {
+			ob = cache_ob->ob;
+			BLI_ghash_insert(gh_objects, ob->id.name, cache_ob->ob);
+		}
+	}
+	/* reasign duplicate objects because memory for particles is not available
+	 * and need to use the original datablock and runtime data */
+	for (int i = 0; i < stl->g_data->gp_cache_used; i++) {
+		cache_ob = &stl->g_data->gp_object_cache[i];
+		if (cache_ob->is_dup_ob) {
+			Object *ob_orig  = (Object *)BLI_ghash_lookup(gh_objects, cache_ob->name);
+			cache_ob->ob = ob_orig;
+			cache_ob->gpd = (bGPdata *)ob_orig->data;
+		}
+	}
+
+	BLI_ghash_free(gh_objects, NULL, NULL);
 
 	/* draw particles */
 	DRW_gpencil_populate_particles(&e_data, vedata);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 00b49152720..48f4dbaf87e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -69,6 +69,7 @@ typedef struct tGPencilObjectCache {
 	struct Object *ob;
 	struct bGPdata *gpd;
 	int idx;  /*original index, can change after sort */
+	char name[66];
 
 	/* effects */
 	bool has_fx;



More information about the Bf-blender-cvs mailing list