[Bf-blender-cvs] [ddc09790d87] blender2.8: DRW: Fix T56418 and T56474 in a more robust way

Clément Foucault noreply at git.blender.org
Wed Aug 22 13:51:27 CEST 2018


Commit: ddc09790d87f078258743477f6372b675a72b7f6
Author: Clément Foucault
Date:   Wed Aug 22 13:41:18 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBddc09790d87f078258743477f6372b675a72b7f6

DRW: Fix T56418 and T56474 in a more robust way

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

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 57ddaa1e16f..b203cbea69e 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -881,6 +881,19 @@ void DRW_drawdata_free(ID *id)
 	BLI_freelistN((ListBase *)drawdata);
 }
 
+/* Unlink (but don't free) the drawdata from the DrawDataList if the ID is an OB from dupli. */
+static void drw_drawdata_unlink_dupli(ID *id)
+{
+	if ((GS(id->name) == ID_OB) && (((Object *)id)->base_flag & BASE_FROMDUPLI) != 0) {
+		DrawDataList *drawdata = DRW_drawdatalist_from_id(id);
+
+		if (drawdata == NULL)
+			return;
+
+		BLI_listbase_clear((ListBase *)drawdata);
+	}
+}
+
 /** \} */
 
 
@@ -944,6 +957,12 @@ static void drw_engines_cache_populate(Object *ob)
 {
 	DST.ob_state = NULL;
 
+	/* HACK: DrawData is copied by COW from the duplicated object.
+	 * This is valid for IDs that cannot be instanciated but this
+	 * is not what we want in this case so we clear the pointer
+	 * ourselves here. */
+	drw_drawdata_unlink_dupli((ID *)ob);
+
 	for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
 		DrawEngineType *engine = link->data;
 		ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
@@ -956,6 +975,10 @@ static void drw_engines_cache_populate(Object *ob)
 			engine->cache_populate(data, ob);
 		}
 	}
+
+	/* ... and clearing it here too because theses draw data are
+	 * from a mempool and must not be free individually by depsgraph. */
+	drw_drawdata_unlink_dupli((ID *)ob);
 }
 
 static void drw_engines_cache_finish(void)



More information about the Bf-blender-cvs mailing list