[Bf-blender-cvs] [1fab889a407] vr_scene_inspection: Fix crash when closing Blender with active VR session

Julian Eisel noreply at git.blender.org
Mon Mar 16 11:22:37 CET 2020


Commit: 1fab889a407d8d496c9071ca38db1bba9ec1eb15
Author: Julian Eisel
Date:   Mon Mar 16 11:12:35 2020 +0100
Branches: vr_scene_inspection
https://developer.blender.org/rB1fab889a407d8d496c9071ca38db1bba9ec1eb15

Fix crash when closing Blender with active VR session

On Windows I still get a crash in some Windows library inside the exit()
call, even though Blender shuts just fine. Not sure where that's coming
from.

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

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

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

diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index 15322fb4c49..746e66735c3 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -235,9 +235,18 @@ wmXrRuntimeData *wm_xr_runtime_data_create(void)
 
 void wm_xr_runtime_data_free(wmXrRuntimeData **runtime)
 {
+  /* Note that this function may be called twice, because of an indirect recursion: If a session is
+   * running while WM-XR calls this function, calling GHOST_XrContextDestroy() will call this
+   * again, because it's also set as the session exit callback. So NULL-check and NULL everything
+   * that is freed here. */
+
+  /* We free all runtime XR data here, so if the context is still alive, destroy it. */
   if ((*runtime)->context != NULL) {
-    GHOST_XrContextDestroy((*runtime)->context);
+    GHOST_XrContextHandle context = (*runtime)->context;
+    /* Prevent recursive GHOST_XrContextDestroy() call by NULL'ing the context pointer before the
+     * first call, see comment above. */
     (*runtime)->context = NULL;
+    GHOST_XrContextDestroy(context);
   }
   MEM_SAFE_FREE(*runtime);
 }



More information about the Bf-blender-cvs mailing list