Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2022-07-27 12:19:48 +0300
committerBastien Montagne <bastien@blender.org>2022-07-27 12:22:48 +0300
commit18dc611b401690c477a97b7d74f4c666c9b41e42 (patch)
treefbbc625f5588f4b682c1eba1a9233b2f96494e55 /source/blender/blenkernel/intern/main_namemap.cc
parent1e55b58e4ff31b10cf9806ca41991346ab3d4513 (diff)
ID namemap: Add check for consistency.
Add a util function to check that content of a given Main and the namemaps in it are consistent. Add some asserts calling this check after file read, and after some override operations.
Diffstat (limited to 'source/blender/blenkernel/intern/main_namemap.cc')
-rw-r--r--source/blender/blenkernel/intern/main_namemap.cc89
1 files changed, 89 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/main_namemap.cc b/source/blender/blenkernel/intern/main_namemap.cc
index 00115d2a0be..3a7b325b3d2 100644
--- a/source/blender/blenkernel/intern/main_namemap.cc
+++ b/source/blender/blenkernel/intern/main_namemap.cc
@@ -22,6 +22,10 @@
#include "MEM_guardedalloc.h"
+#include "CLG_log.h"
+
+static CLG_LogRef LOG = {"bke.main_namemap"};
+
//#define DEBUG_PRINT_MEMORY_USAGE
using namespace blender;
@@ -363,3 +367,88 @@ void BKE_main_namemap_remove_name(struct Main *bmain, struct ID *id, const char
}
val->mark_unused(number);
}
+
+struct Uniqueness_Key {
+ char name[MAX_ID_NAME];
+ Library *lib;
+ uint64_t hash() const
+ {
+ return BLI_ghashutil_combine_hash(BLI_ghashutil_strhash_n(name, MAX_ID_NAME),
+ BLI_ghashutil_ptrhash(lib));
+ }
+ bool operator==(const Uniqueness_Key &o) const
+ {
+ return lib == o.lib && !BLI_ghashutil_strcmp(name, o.name);
+ }
+};
+
+bool BKE_main_namemap_validate(Main *bmain)
+{
+ Set<Uniqueness_Key> id_names_libs;
+ bool is_valid = true;
+ ID *id_iter;
+ FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
+ Uniqueness_Key key;
+ BLI_strncpy(key.name, id_iter->name, MAX_ID_NAME);
+ key.lib = id_iter->lib;
+ if (!id_names_libs.add(key)) {
+ is_valid = false;
+ CLOG_ERROR(&LOG,
+ "ID name '%s' (from library '%s') is found more than once",
+ id_iter->name,
+ id_iter->lib != nullptr ? id_iter->lib->filepath : "<None>");
+ }
+
+ UniqueName_Map *name_map = get_namemap_for(bmain, id_iter, false);
+ if (name_map == nullptr) {
+ continue;
+ }
+ UniqueName_TypeMap *type_map = name_map->find_by_type(GS(id_iter->name));
+ BLI_assert(type_map != nullptr);
+
+ UniqueName_Key key_namemap;
+ /* Remove full name from the set. */
+ BLI_strncpy(key_namemap.name, id_iter->name + 2, MAX_NAME);
+ if (!type_map->full_names.contains(key_namemap)) {
+ is_valid = false;
+ CLOG_ERROR(&LOG,
+ "ID name '%s' (from library '%s') exists in current Main, but is not listed in "
+ "the namemap",
+ id_iter->name,
+ id_iter->lib != nullptr ? id_iter->lib->filepath : "<None>");
+ }
+ }
+ FOREACH_MAIN_ID_END;
+
+ Library *lib = nullptr;
+ UniqueName_Map *name_map = bmain->name_map;
+ do {
+ if (name_map != nullptr) {
+ int i = 0;
+ for (short idcode = BKE_idtype_idcode_iter_step(&i); idcode != 0;
+ idcode = BKE_idtype_idcode_iter_step(&i)) {
+ UniqueName_TypeMap *type_map = name_map->find_by_type(idcode);
+ if (type_map != nullptr) {
+ for (const UniqueName_Key &id_name : type_map->full_names) {
+ Uniqueness_Key key;
+ *(reinterpret_cast<short *>(key.name)) = idcode;
+ BLI_strncpy(key.name + 2, id_name.name, MAX_NAME);
+ key.lib = lib;
+ if (!id_names_libs.contains(key)) {
+ is_valid = false;
+ CLOG_ERROR(&LOG,
+ "ID name '%s' (from library '%s') is listed in the namemap, but does not "
+ "exists in current Main",
+ key.name,
+ lib != nullptr ? lib->filepath : "<None>");
+ }
+ }
+ }
+ }
+ }
+ lib = static_cast<Library *>((lib == nullptr) ? bmain->libraries.first : lib->id.next);
+ name_map = (lib != nullptr) ? lib->runtime.name_map : nullptr;
+ } while (lib != nullptr);
+
+ return is_valid;
+}