[Bf-blender-cvs] [cb9c0aa7d02] master: Fix: XR action map memory leaks

Peter Kim noreply at git.blender.org
Wed Aug 25 14:20:43 CEST 2021


Commit: cb9c0aa7d02e1b505b9af5d79e8603f70471e9ab
Author: Peter Kim
Date:   Wed Aug 25 20:45:25 2021 +0900
Branches: master
https://developer.blender.org/rBcb9c0aa7d02e1b505b9af5d79e8603f70471e9ab

Fix: XR action map memory leaks

This fixes two memory leaks related to XR action maps.

1. Freeing of action maps needs to be moved from wm_xr_exit() to
wm_xr_runtime_data_free() since the runtime may have already been
freed when calling wm_xr_exit().

2. Action bindings for action map items were not being freed. This
was mistakenly left out of e844e9e8f3bb since the patch needed to be
updated after d3d4be1db3a0.

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

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

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

diff --git a/source/blender/windowmanager/xr/intern/wm_xr.c b/source/blender/windowmanager/xr/intern/wm_xr.c
index 3091a3a19f1..cffe14a2146 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr.c
@@ -115,7 +115,6 @@ bool wm_xr_init(wmWindowManager *wm)
 void wm_xr_exit(wmWindowManager *wm)
 {
   if (wm->xr.runtime != NULL) {
-    WM_xr_actionmaps_clear(wm->xr.runtime);
     wm_xr_runtime_data_free(&wm->xr.runtime);
   }
   if (wm->xr.session_settings.shading.prop) {
@@ -166,6 +165,9 @@ void wm_xr_runtime_data_free(wmXrRuntimeData **runtime)
     /* Prevent recursive GHOST_XrContextDestroy() call by NULL'ing the context pointer before the
      * first call, see comment above. */
     (*runtime)->context = NULL;
+
+    WM_xr_actionmaps_clear(*runtime);
+
     GHOST_XrContextDestroy(context);
   }
   MEM_SAFE_FREE(*runtime);
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c b/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c
index f9ad34b5a9b..673fdfcd602 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c
@@ -178,6 +178,12 @@ XrActionMapBinding *WM_xr_actionmap_binding_find(XrActionMapItem *ami, const cha
  * Item in an XR action map, that maps an XR event to an operator, pose, or haptic output.
  * \{ */
 
+static void wm_xr_actionmap_item_bindings_clear(XrActionMapItem *ami)
+{
+  BLI_freelistN(&ami->bindings);
+  ami->selbinding = -1;
+}
+
 static void wm_xr_actionmap_item_properties_set(XrActionMapItem *ami)
 {
   WM_operator_properties_alloc(&(ami->op_properties_ptr), &(ami->op_properties), ami->op);
@@ -345,10 +351,8 @@ bool WM_xr_actionmap_item_remove(XrActionMap *actionmap, XrActionMapItem *ami)
   int idx = BLI_findindex(&actionmap->items, ami);
 
   if (idx != -1) {
-    if (ami->op_properties_ptr) {
-      WM_operator_properties_free(ami->op_properties_ptr);
-      MEM_freeN(ami->op_properties_ptr);
-    }
+    wm_xr_actionmap_item_bindings_clear(ami);
+    wm_xr_actionmap_item_properties_free(ami);
     BLI_freelinkN(&actionmap->items, ami);
 
     if (BLI_listbase_is_empty(&actionmap->items)) {
@@ -518,6 +522,7 @@ XrActionMap *WM_xr_actionmap_find(wmXrRuntimeData *runtime, const char *name)
 void WM_xr_actionmap_clear(XrActionMap *actionmap)
 {
   LISTBASE_FOREACH (XrActionMapItem *, ami, &actionmap->items) {
+    wm_xr_actionmap_item_bindings_clear(ami);
     wm_xr_actionmap_item_properties_free(ami);
   }



More information about the Bf-blender-cvs mailing list