[Bf-blender-cvs] [03ff58b67d5] master: Cleanup: Use const qualifier in modifier data copy

Sergey Sharybin noreply at git.blender.org
Wed Feb 16 15:40:11 CET 2022


Commit: 03ff58b67d50a714c5609e584a6942996cfdee1b
Author: Sergey Sharybin
Date:   Wed Feb 16 11:56:04 2022 +0100
Branches: master
https://developer.blender.org/rB03ff58b67d50a714c5609e584a6942996cfdee1b

Cleanup: Use const qualifier in modifier data copy

Fix possible overflow of Modifier UUID

The code prior this change was re-generating modifier's session UUID
prior to copying this id from the source. This approach has a higher
risk of modifiers session UUID to overflow and start colliding with
existing modifiers.

This change makes it so that modifier copy does not re-generated the
session UUID unless it is needed.

Differential Revision: https://developer.blender.org/D14125

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

M	source/blender/blenkernel/BKE_modifier.h
M	source/blender/blenkernel/intern/modifier.c
M	source/blender/blenkernel/intern/object.cc

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

diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index 6df503153b9..acdca23b21c 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -409,6 +409,8 @@ void BKE_modifier_session_uuid_generate(struct ModifierData *md);
 
 bool BKE_modifier_unique_name(struct ListBase *modifiers, struct ModifierData *md);
 
+struct ModifierData *BKE_modifier_copy_ex(const struct ModifierData *md, int flag);
+
 /**
  * Callback's can use this to avoid copying every member.
  */
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 0e8838d16ce..837c1fe179f 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -131,7 +131,7 @@ void BKE_modifier_panel_expand(ModifierData *md)
 
 /***/
 
-ModifierData *BKE_modifier_new(int type)
+static ModifierData *modifier_allocate_and_init(int type)
 {
   const ModifierTypeInfo *mti = BKE_modifier_get_info(type);
   ModifierData *md = MEM_callocN(mti->structSize, mti->structName);
@@ -152,6 +152,13 @@ ModifierData *BKE_modifier_new(int type)
     mti->initData(md);
   }
 
+  return md;
+}
+
+ModifierData *BKE_modifier_new(int type)
+{
+  ModifierData *md = modifier_allocate_and_init(type);
+
   BKE_modifier_session_uuid_generate(md);
 
   return md;
@@ -315,6 +322,16 @@ void BKE_modifiers_foreach_tex_link(Object *ob, TexWalkFunc walk, void *userData
   }
 }
 
+ModifierData *BKE_modifier_copy_ex(const ModifierData *md, int flag)
+{
+  ModifierData *md_dst = modifier_allocate_and_init(md->type);
+
+  BLI_strncpy(md_dst->name, md->name, sizeof(md_dst->name));
+  BKE_modifier_copydata_ex(md, md_dst, flag);
+
+  return md_dst;
+}
+
 void BKE_modifier_copydata_generic(const ModifierData *md_src,
                                    ModifierData *md_dst,
                                    const int UNUSED(flag))
diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index 579e61750f0..3a8d7d6bc8a 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -1599,9 +1599,7 @@ bool BKE_object_modifier_stack_copy(Object *ob_dst,
       continue;
     }
 
-    ModifierData *md_dst = BKE_modifier_new(md_src->type);
-    BLI_strncpy(md_dst->name, md_src->name, sizeof(md_dst->name));
-    BKE_modifier_copydata_ex(md_src, md_dst, flag_subdata);
+    ModifierData *md_dst = BKE_modifier_copy_ex(md_src, flag_subdata);
     BLI_addtail(&ob_dst->modifiers, md_dst);
   }



More information about the Bf-blender-cvs mailing list