[Bf-blender-cvs] [deb78d4f207] uuid-id: Make session-wise uuid increment atomic, and reset it on file load.
Bastien Montagne
noreply at git.blender.org
Thu Mar 5 15:26:29 CET 2020
Commit: deb78d4f207435d993ac801aa27cb564cd6afb08
Author: Bastien Montagne
Date: Thu Mar 5 15:24:24 2020 +0100
Branches: uuid-id
https://developer.blender.org/rBdeb78d4f207435d993ac801aa27cb564cd6afb08
Make session-wise uuid increment atomic, and reset it on file load.
Reseting on file load should avoid almost all possible case of counter
overflow, and makes sense anyway, since loading a file fully
resets/restarts an editing session.
===================================================================
M source/blender/blenkernel/BKE_lib_id.h
M source/blender/blenkernel/intern/lib_id.c
M source/blender/windowmanager/intern/wm_files.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h
index 4ce5691543f..27dd1e637f3 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -72,6 +72,7 @@ void BKE_libblock_init_empty(struct ID *id) ATTR_NONNULL(1);
/* When an ID's uuid is of that value, it is unset/invalid (e.g. for runtime IDs, etc.). */
#define MAIN_ID_SESSION_UUID_UNSET 0
+void BKE_lib_libblock_session_uuid_reset(void);
void BKE_lib_libblock_session_uuid_ensure(struct ID *id);
void *BKE_id_new(struct Main *bmain, const short type, const char *name);
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 4d102e6049c..0c8ecfc0a2b 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -1460,18 +1460,32 @@ void BKE_libblock_init_empty(ID *id)
}
}
-/** Generate a session-wise uuid for the given \a id. */
-void BKE_lib_libblock_session_uuid_ensure(ID *id)
+/* ********** ID session-wise UUID management. ********** */
+static uint global_session_uuid = 0;
+
+/** Reset the session-wise uuid counter (used when reading a new file e.g.). */
+void BKE_lib_libblock_session_uuid_reset()
{
- static uint global_session_uuid = 0;
+ printf("Reset session-wise UUID counter\n");
+ global_session_uuid = 0;
+}
+/**
+ * Generate a session-wise uuid for the given \a id.
+ *
+ * \note "session-wise" here means while editing a given .blend file. Once a new .blend file is
+ * loaded or created, undo history is cleared/reset, and so is the uuid counter.
+ */
+void BKE_lib_libblock_session_uuid_ensure(ID *id)
+{
if (id->session_uuid == MAIN_ID_SESSION_UUID_UNSET) {
- id->session_uuid = ++global_session_uuid;
+ id->session_uuid = atomic_add_and_fetch_uint32(&global_session_uuid, 1);
/* In case overflow happens, still assign a valid ID. This way opening files many times works
* correctly. */
- if (id->session_uuid == MAIN_ID_SESSION_UUID_UNSET) {
- id->session_uuid = ++global_session_uuid;
+ if (UNLIKELY(id->session_uuid == MAIN_ID_SESSION_UUID_UNSET)) {
+ id->session_uuid = atomic_add_and_fetch_uint32(&global_session_uuid, 1);
}
+ printf("\tassigned uuid %u to %s\n", id->session_uuid, id->name);
}
}
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index dae6f62319d..2dcacc3dc30 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -77,6 +77,7 @@
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
+#include "BKE_lib_id.h"
#include "BKE_lib_override.h"
#include "BKE_main.h"
#include "BKE_packedFile.h"
@@ -611,6 +612,9 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
UI_view2d_zoom_cache_reset();
+ /* Reset session-wise ID UUID counter. */
+ BKE_lib_libblock_session_uuid_reset();
+
/* first try to append data from exotic file formats... */
/* it throws error box when file doesn't exist and returns -1 */
/* note; it should set some error message somewhere... (ton) */
@@ -917,6 +921,9 @@ void wm_homefile_read(bContext *C,
}
}
+ /* Reset session-wise ID UUID counter. */
+ BKE_lib_libblock_session_uuid_reset();
+
if (!use_factory_settings || (filepath_startup[0] != '\0')) {
if (BLI_access(filepath_startup, R_OK) == 0) {
success = BKE_blendfile_read(C,
More information about the Bf-blender-cvs
mailing list