[Bf-blender-cvs] [c42fc19a8a1] blender2.8: Fix crash when drag&drop invisible object from outliner to viewport

Dalai Felinto noreply at git.blender.org
Thu Jan 25 13:02:00 CET 2018


Commit: c42fc19a8a1c71a8a20f70aa4daa9813081b9dfb
Author: Dalai Felinto
Date:   Thu Jan 25 09:26:15 2018 -0200
Branches: blender2.8
https://developer.blender.org/rBc42fc19a8a1c71a8a20f70aa4daa9813081b9dfb

Fix crash when drag&drop invisible object from outliner to viewport

This is not the issue actually mentioned there. However it is the most serious
one.

Now if the object being dragged was not in a collection linked in the viewlayer
or invisible, we add it to the active collection (or create one if necessary).

This is related to T50967, which is now fully fixed.

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

M	source/blender/editors/object/object_add.c

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

diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 0fc2b58ff9f..786784a200f 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -2086,7 +2086,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, ViewLayer
 #define ID_NEW_REMAP_US(a)	if (      (a)->id.newid) { (a) = (void *)(a)->id.newid;       (a)->id.us++; }
 #define ID_NEW_REMAP_US2(a)	if (((ID *)a)->newid)    { (a) = ((ID  *)a)->newid;     ((ID *)a)->us++;    }
 
-	Base *basen = NULL;
+	Base *base, *basen = NULL;
 	Material ***matarar;
 	Object *obn;
 	ID *id;
@@ -2099,7 +2099,14 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, ViewLayer
 		obn = ID_NEW_SET(ob, BKE_object_copy(bmain, ob));
 		DEG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
 
-		BKE_collection_object_add_from(scene, ob, obn);
+		base = BKE_view_layer_base_find(view_layer, ob);
+		if ((base != NULL) && (base->flag & BASE_VISIBLED)) {
+			BKE_collection_object_add_from(scene, ob, obn);
+		}
+		else {
+			LayerCollection *layer_collection = BKE_layer_collection_get_active_ensure(scene, view_layer);
+			BKE_collection_object_add(&scene->id, layer_collection->scene_collection, obn);
+		}
 		basen = BKE_view_layer_base_find(view_layer, obn);
 
 		/* 1) duplis should end up in same group as the original
@@ -2449,13 +2456,13 @@ static int add_named_exec(bContext *C, wmOperator *op)
 	clear_sca_new_poins();  /* BGE logic */
 
 	basen = object_add_duplicate_internal(bmain, scene, view_layer, ob, dupflag);
-	BKE_scene_object_base_flag_sync_from_object(basen);
 
 	if (basen == NULL) {
 		BKE_report(op->reports, RPT_ERROR, "Object could not be duplicated");
 		return OPERATOR_CANCELLED;
 	}
 
+	BKE_scene_object_base_flag_sync_from_object(basen);
 	basen->object->restrictflag &= ~OB_RESTRICT_VIEW;
 
 	if (event) {
@@ -2473,8 +2480,12 @@ static int add_named_exec(bContext *C, wmOperator *op)
 
 	BKE_main_id_clear_newpoins(bmain);
 
+	/* TODO(sergey): Only update relations for the current scene. */
 	DEG_relations_tag_update(bmain);
 
+	/* TODO(sergey): Use proper flag for tagging here. */
+	DEG_id_tag_update(&scene->id, 0);
+
 	WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
 	WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);



More information about the Bf-blender-cvs mailing list