[Bf-blender-cvs] [35ca2a8737e] temp-lineart-contained: IDRemap: Add option to also remap internal runtime ID pointers.

Bastien Montagne noreply at git.blender.org
Sat Mar 13 02:01:00 CET 2021


Commit: 35ca2a8737e7cfbc1bb3bf79cc507a81c14ba6c0
Author: Bastien Montagne
Date:   Fri Mar 12 09:41:00 2021 +0100
Branches: temp-lineart-contained
https://developer.blender.org/rB35ca2a8737e7cfbc1bb3bf79cc507a81c14ba6c0

IDRemap: Add option to also remap internal runtime ID pointers.

In some cases (advanced, low-level), we also want to remap pointers like
`ID.newid` or `ID.orig_id`.

Only known case currently is `id_delete`, to avoid leaving potential access to freed memory. See next commit and T86501.

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

M	source/blender/blenkernel/BKE_lib_remap.h
M	source/blender/blenkernel/intern/lib_remap.c

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

diff --git a/source/blender/blenkernel/BKE_lib_remap.h b/source/blender/blenkernel/BKE_lib_remap.h
index 6e81273b82b..705d2b030e5 100644
--- a/source/blender/blenkernel/BKE_lib_remap.h
+++ b/source/blender/blenkernel/BKE_lib_remap.h
@@ -78,6 +78,13 @@ enum {
   ID_REMAP_SKIP_OVERRIDE_LIBRARY = 1 << 5,
   /** Don't touch the user count (use for low level actions such as swapping pointers). */
   ID_REMAP_SKIP_USER_CLEAR = 1 << 6,
+  /**
+   * Force internal ID runtime pointers (like `ID.newid`, `ID.orig_id` etc.) to also be processed.
+   * This should only be needed in some very specific cases, typically only BKE ID management code
+   * should need it (e.g. required from `id_delete` to ensure no runtime pointer remains using
+   * freed ones).
+   */
+  ID_REMAP_FORCE_INTERNAL_RUNTIME_POINTERS = 1 << 7,
 };
 
 /* Note: Requiring new_id to be non-null, this *may* not be the case ultimately,
diff --git a/source/blender/blenkernel/intern/lib_remap.c b/source/blender/blenkernel/intern/lib_remap.c
index 0218cb913a8..1f597bbb9a6 100644
--- a/source/blender/blenkernel/intern/lib_remap.c
+++ b/source/blender/blenkernel/intern/lib_remap.c
@@ -373,9 +373,12 @@ static void libblock_remap_data(
     Main *bmain, ID *id, ID *old_id, ID *new_id, const short remap_flags, IDRemap *r_id_remap_data)
 {
   IDRemap id_remap_data;
-  const int foreach_id_flags = (remap_flags & ID_REMAP_NO_INDIRECT_PROXY_DATA_USAGE) != 0 ?
-                                   IDWALK_NO_INDIRECT_PROXY_DATA_USAGE :
-                                   IDWALK_NOP;
+  const int foreach_id_flags = ((remap_flags & ID_REMAP_NO_INDIRECT_PROXY_DATA_USAGE) != 0 ?
+                                    IDWALK_NO_INDIRECT_PROXY_DATA_USAGE :
+                                    IDWALK_NOP) |
+                               ((remap_flags & ID_REMAP_FORCE_INTERNAL_RUNTIME_POINTERS) != 0 ?
+                                    IDWALK_DO_INTERNAL_RUNTIME_POINTERS :
+                                    IDWALK_NOP);
 
   if (r_id_remap_data == NULL) {
     r_id_remap_data = &id_remap_data;



More information about the Bf-blender-cvs mailing list