[Bf-blender-cvs] [66328db703b] blender-v3.1-release: Fix T95636: Dragging Material from Asset Browser (Link mode) to Viewport empty space removes this material from all objects

Bastien Montagne noreply at git.blender.org
Fri Feb 25 11:40:04 CET 2022


Commit: 66328db703bba8196f159d15d9632c34d845892d
Author: Bastien Montagne
Date:   Fri Feb 25 11:37:55 2022 +0100
Branches: blender-v3.1-release
https://developer.blender.org/rB66328db703bba8196f159d15d9632c34d845892d

Fix T95636: Dragging Material from Asset Browser (Link mode) to Viewport empty space removes this material from all objects

Trust user count to actually delete or not the dragged ID when current
dragging is cancelled, since it may be already used by others.

NOTE: This is more a band-aid fix than anything else, cancelling drag
has a lot of other issues here (like never deleting any indirectly
linked/appended data, etc.). It needs a proper rethink in general.

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

M	source/blender/windowmanager/intern/wm_dragdrop.c

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

diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index 96cb66b44ea..9610960d178 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -620,8 +620,12 @@ void WM_drag_free_imported_drag_ID(struct Main *bmain, wmDrag *drag, wmDropBox *
   }
 
   ID *id = BKE_libblock_find_name(bmain, asset_drag->id_type, name);
-  if (id) {
-    BKE_id_delete(bmain, id);
+  if (id != NULL) {
+    /* Do not delete the dragged ID if it has any user, otherwise if it is a 're-used' ID it will
+     * cause T95636. Note that we need first to add the user that we want to remove in
+     * #BKE_id_free_us. */
+    id_us_plus(id);
+    BKE_id_free_us(bmain, id);
   }
 }



More information about the Bf-blender-cvs mailing list