[Bf-blender-cvs] [b723d388126] master: Add utils to remove an ID from the relations runtime data in Main.

Bastien Montagne noreply at git.blender.org
Mon Jun 29 17:28:09 CEST 2020


Commit: b723d3881266c4cd93e57959b476982d2879c15c
Author: Bastien Montagne
Date:   Fri Jun 26 17:50:23 2020 +0200
Branches: master
https://developer.blender.org/rBb723d3881266c4cd93e57959b476982d2879c15c

Add utils to remove an ID from the relations runtime data in Main.

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

M	source/blender/blenkernel/BKE_main.h
M	source/blender/blenkernel/intern/main.c

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

diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index 516148728d2..b7c70168a49 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -173,6 +173,7 @@ void BKE_main_unlock(struct Main *bmain);
 
 void BKE_main_relations_create(struct Main *bmain, const short flag);
 void BKE_main_relations_free(struct Main *bmain);
+void BKE_main_relations_ID_remove(struct Main *bmain, struct ID *id);
 
 struct GSet *BKE_main_gset_create(struct Main *bmain, struct GSet *gset);
 
diff --git a/source/blender/blenkernel/intern/main.c b/source/blender/blenkernel/intern/main.c
index ea3bee8b2f6..4b577ccec2c 100644
--- a/source/blender/blenkernel/intern/main.c
+++ b/source/blender/blenkernel/intern/main.c
@@ -287,6 +287,29 @@ void BKE_main_relations_free(Main *bmain)
   }
 }
 
+/**
+ * Remove an ID from the relations (the two entries for that ID, not the ID from entries in other
+ * IDs' relationships).
+ *
+ * Does not free any allocated memory.
+ * Allows to use those relations as a way to mark an ID as already processed, without requiring any
+ * additional tagging or GSet.
+ * Obviously, relations should be freed after use then, since this will make them fully invalid.
+ */
+void BKE_main_relations_ID_remove(Main *bmain, ID *id)
+{
+  if (bmain->relations) {
+    /* Note: we do not free the entries from the mempool, those will be dealt with when finally
+     * freeing the whole relations. */
+    if (bmain->relations->id_used_to_user) {
+      BLI_ghash_remove(bmain->relations->id_used_to_user, id, NULL, NULL);
+    }
+    if (bmain->relations->id_user_to_used) {
+      BLI_ghash_remove(bmain->relations->id_user_to_used, id, NULL, NULL);
+    }
+  }
+}
+
 /**
  * Create a GSet storing all IDs present in given \a bmain, by their pointers.
  *



More information about the Bf-blender-cvs mailing list