[Bf-blender-cvs] [894269ad124] master: Fix incorrect copying of XR action map items

Peter Kim noreply at git.blender.org
Thu Dec 9 08:29:23 CET 2021


Commit: 894269ad12469fb37904d4ca5a47ffd15b328e59
Author: Peter Kim
Date:   Thu Dec 9 16:29:05 2021 +0900
Branches: master
https://developer.blender.org/rB894269ad12469fb37904d4ca5a47ffd15b328e59

Fix incorrect copying of XR action map items

After using MEM_dupallocN() on the original item, the bindings ListBase
for the new item needs to be cleared and each binding copied separately.

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

M	source/blender/windowmanager/xr/intern/wm_xr_actionmap.c

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

diff --git a/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c b/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c
index 8c38b8f0360..076f279ccbb 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c
@@ -115,7 +115,6 @@ void WM_xr_actionmap_binding_ensure_unique(XrActionMapItem *ami, XrActionMapBind
 static XrActionMapBinding *wm_xr_actionmap_binding_copy(XrActionMapBinding *amb_src)
 {
   XrActionMapBinding *amb_dst = MEM_dupallocN(amb_src);
-
   amb_dst->prev = amb_dst->next = NULL;
 
   return amb_dst;
@@ -298,25 +297,29 @@ void WM_xr_actionmap_item_ensure_unique(XrActionMap *actionmap, XrActionMapItem
   BLI_strncpy(ami->name, name, MAX_NAME);
 }
 
-static XrActionMapItem *wm_xr_actionmap_item_copy(XrActionMapItem *ami)
+static XrActionMapItem *wm_xr_actionmap_item_copy(XrActionMapItem *ami_src)
 {
-  XrActionMapItem *amin = MEM_dupallocN(ami);
-
-  amin->prev = amin->next = NULL;
+  XrActionMapItem *ami_dst = MEM_dupallocN(ami_src);
+  ami_dst->prev = ami_dst->next = NULL;
 
-  if (amin->op_properties) {
-    amin->op_properties_ptr = MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr");
-    WM_operator_properties_create(amin->op_properties_ptr, amin->op);
+  BLI_listbase_clear(&ami_dst->bindings);
+  LISTBASE_FOREACH (XrActionMapBinding *, amb, &ami_src->bindings) {
+    XrActionMapBinding *amb_new = wm_xr_actionmap_binding_copy(amb);
+    BLI_addtail(&ami_dst->bindings, amb_new);
+  }
 
-    amin->op_properties = IDP_CopyProperty(amin->op_properties);
-    amin->op_properties_ptr->data = amin->op_properties;
+  if (ami_dst->op_properties) {
+    ami_dst->op_properties_ptr = MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr");
+    WM_operator_properties_create(ami_dst->op_properties_ptr, ami_dst->op);
+    ami_dst->op_properties = IDP_CopyProperty(ami_src->op_properties);
+    ami_dst->op_properties_ptr->data = ami_dst->op_properties;
   }
   else {
-    amin->op_properties = NULL;
-    amin->op_properties_ptr = NULL;
+    ami_dst->op_properties = NULL;
+    ami_dst->op_properties_ptr = NULL;
   }
 
-  return amin;
+  return ami_dst;
 }
 
 XrActionMapItem *WM_xr_actionmap_item_add_copy(XrActionMap *actionmap, XrActionMapItem *ami_src)
@@ -431,10 +434,9 @@ void WM_xr_actionmap_ensure_unique(wmXrRuntimeData *runtime, XrActionMap *action
 static XrActionMap *wm_xr_actionmap_copy(XrActionMap *am_src)
 {
   XrActionMap *am_dst = MEM_dupallocN(am_src);
-
   am_dst->prev = am_dst->next = NULL;
-  BLI_listbase_clear(&am_dst->items);
 
+  BLI_listbase_clear(&am_dst->items);
   LISTBASE_FOREACH (XrActionMapItem *, ami, &am_src->items) {
     XrActionMapItem *ami_new = wm_xr_actionmap_item_copy(ami);
     BLI_addtail(&am_dst->items, ami_new);



More information about the Bf-blender-cvs mailing list