[Bf-blender-cvs] [f126ce2d5b7] xr-actions-D9124: Add safety checks when accessing XR window and controller objects.
Peter Kim
noreply at git.blender.org
Tue Oct 13 14:45:02 CEST 2020
Commit: f126ce2d5b765f11acec8c12035c3ecfda738a8e
Author: Peter Kim
Date: Sun Oct 11 20:13:28 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rBf126ce2d5b765f11acec8c12035c3ecfda738a8e
Add safety checks when accessing XR window and controller objects.
===================================================================
M source/blender/draw/engines/overlay/overlay_xr.c
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/windowmanager/intern/wm_event_system.c
M source/blender/windowmanager/xr/intern/wm_xr_intern.h
M source/blender/windowmanager/xr/intern/wm_xr_session.c
===================================================================
diff --git a/source/blender/draw/engines/overlay/overlay_xr.c b/source/blender/draw/engines/overlay/overlay_xr.c
index 01c9fe4c0b5..ba9c8c16646 100644
--- a/source/blender/draw/engines/overlay/overlay_xr.c
+++ b/source/blender/draw/engines/overlay/overlay_xr.c
@@ -31,9 +31,10 @@ void OVERLAY_xr_cache_init(OVERLAY_Data *vedata)
OVERLAY_PassList *psl = vedata->psl;
OVERLAY_PrivateData *pd = vedata->stl->pd;
DRWShadingGroup *grp;
- const float color[4] = { 0.211f, 0.219f, 0.223f, 0.4f };
+ const float color[4] = {0.211f, 0.219f, 0.223f, 0.4f};
- DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND_ALPHA;
+ DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL |
+ DRW_STATE_BLEND_ALPHA;
DRW_PASS_CREATE(psl->xr_controllers_ps, state | pd->clipping_state);
GPUShader *sh = OVERLAY_shader_uniform_color();
@@ -46,12 +47,13 @@ void OVERLAY_xr_cache_populate(OVERLAY_Data *vedata, Object *ob)
OVERLAY_PrivateData *pd = vedata->stl->pd;
GPUBatch *xr_controllers = DRW_cache_mesh_all_verts_get(ob);
- if (xr_controllers && xr_controllers->verts[0] && (GPU_vertbuf_get_vertex_len(xr_controllers->verts[0]) > 0)) {
+ if (xr_controllers && xr_controllers->verts[0] &&
+ (GPU_vertbuf_get_vertex_len(xr_controllers->verts[0]) > 0)) {
DRW_shgroup_call_obmat(pd->xr_controllers_grp, xr_controllers, ob->obmat);
}
else {
/* Fallback to primitive sphere. */
- const float scale[3] = { 0.05f, 0.05f, 0.05f };
+ const float scale[3] = {0.05f, 0.05f, 0.05f};
float obmat[4][4];
copy_m4_m4(obmat, ob->obmat);
rescale_m4(obmat, scale);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 364c79a9578..d7b0e3ea3bd 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1807,8 +1807,8 @@ void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph,
}
/* Disable other overlays (set all available _HIDE_ flags). */
v3d.overlay.flag |= V3D_OVERLAY_HIDE_CURSOR | V3D_OVERLAY_HIDE_TEXT |
- V3D_OVERLAY_HIDE_MOTION_PATHS | V3D_OVERLAY_HIDE_BONES |
- V3D_OVERLAY_HIDE_OBJECT_XTRAS | V3D_OVERLAY_HIDE_OBJECT_ORIGINS;
+ V3D_OVERLAY_HIDE_MOTION_PATHS | V3D_OVERLAY_HIDE_BONES |
+ V3D_OVERLAY_HIDE_OBJECT_XTRAS | V3D_OVERLAY_HIDE_OBJECT_ORIGINS;
v3d.flag |= V3D_HIDE_HELPLINES;
}
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 81baf956509..fdf4d71c6a5 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -3188,6 +3188,9 @@ static void wm_event_surface_free_all(wmXrSurfaceData *surface_data)
static void wm_event_do_surface_handlers(bContext *C, wmSurface *surface)
{
+ /* TODO_XR: Currently assumes that the XR surface is the
+ * same as the one for the XR runtime. In the future this
+ * might not always be the case. */
wmWindowManager *wm = CTX_wm_manager(C);
wmXrData *xr = &wm->xr;
if (!xr->runtime || !surface->is_xr) {
@@ -3199,13 +3202,9 @@ static void wm_event_do_surface_handlers(bContext *C, wmSurface *surface)
return;
}
- /* TODO_XR: Currently assumes that the XR surface is the
- * same as the one for the runtime. In the future this
- * might not always be the case. */
- wmWindow *win = xr->runtime->session_root_win;
+ wmWindow *win = wm_xr_session_root_window_or_fallback_get(wm, xr->runtime);
bScreen *screen = WM_window_get_active_screen(win);
- /* some safety checks - these should always be set! */
BLI_assert(WM_window_get_active_scene(win));
BLI_assert(WM_window_get_active_screen(win));
BLI_assert(WM_window_get_active_workspace(win));
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_intern.h b/source/blender/windowmanager/xr/intern/wm_xr_intern.h
index 728c4345969..cbc78eb800e 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_intern.h
+++ b/source/blender/windowmanager/xr/intern/wm_xr_intern.h
@@ -139,6 +139,8 @@ typedef struct wmXrActionSet {
wmXrRuntimeData *wm_xr_runtime_data_create(void);
void wm_xr_runtime_data_free(wmXrRuntimeData **runtime);
+wmWindow *wm_xr_session_root_window_or_fallback_get(const wmWindowManager *wm,
+ const wmXrRuntimeData *runtime_data);
void wm_xr_session_draw_data_update(const wmXrSessionState *state,
const XrSessionSettings *settings,
const GHOST_XrDrawViewInfo *draw_view,
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c
index 216ea23c082..dfdb832a1f2 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_session.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c
@@ -20,6 +20,7 @@
#include "BKE_callbacks.h"
#include "BKE_context.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_scene.h"
@@ -191,8 +192,8 @@ static void wm_xr_session_draw_data_populate(wmXrData *xr_data,
wm_xr_session_base_pose_calc(r_draw_data->scene, settings, &r_draw_data->base_pose);
}
-static wmWindow *wm_xr_session_root_window_or_fallback_get(const wmWindowManager *wm,
- const wmXrRuntimeData *runtime_data)
+wmWindow *wm_xr_session_root_window_or_fallback_get(const wmWindowManager *wm,
+ const wmXrRuntimeData *runtime_data)
{
if (runtime_data->session_root_win &&
BLI_findindex(&wm->windows, runtime_data->session_root_win) != -1) {
@@ -462,7 +463,8 @@ void wm_xr_session_actions_init(wmXrData *xr)
static void wm_xr_session_controller_mats_update(const XrSessionSettings *settings,
const wmXrAction *controller_pose_action,
- wmXrSessionState *state)
+ wmXrSessionState *state,
+ ViewLayer *view_layer)
{
const unsigned int count = min(controller_pose_action->count_subaction_paths, 2);
@@ -492,11 +494,14 @@ static void wm_xr_session_controller_mats_update(const XrSessionSettings *settin
mat4_to_loc_quat(
controller->pose.position, controller->pose.orientation_quat, controller->mat);
- /* TODO_XR: Check if object was deleted by user. */
if (controller->ob) {
- copy_v3_v3(controller->ob->loc, controller->pose.position);
- quat_to_eul(controller->ob->rot, controller->pose.orientation_quat);
- DEG_id_tag_update(&controller->ob->id, ID_RECALC_TRANSFORM);
+ /* TODO_XR: Handle case where object was deleted but then undone. */
+ Base *base = BKE_view_layer_base_find(view_layer, controller->ob);
+ if (base) {
+ copy_v3_v3(controller->ob->loc, controller->pose.position);
+ quat_to_eul(controller->ob->rot, controller->pose.orientation_quat);
+ DEG_id_tag_update(&controller->ob->id, ID_RECALC_TRANSFORM);
+ }
}
}
}
@@ -623,6 +628,7 @@ static void wm_xr_session_action_set_update(const XrSessionSettings *settings,
GHOST_XrContextHandle xr_context,
wmXrSessionState *state,
wmXrActionSet *action_set,
+ ViewLayer *view_layer,
wmSurface *surface,
wmWindow *win)
{
@@ -657,7 +663,8 @@ static void wm_xr_session_action_set_update(const XrSessionSettings *settings,
if (ret &&
(action_set == state->active_action_set)) { /* Only dispatch events for active action set. */
if (action_set->controller_pose_action) {
- wm_xr_session_controller_mats_update(settings, action_set->controller_pose_action, state);
+ wm_xr_session_controller_mats_update(
+ settings, action_set->controller_pose_action, state, view_layer);
}
if (surface && win) {
@@ -672,13 +679,13 @@ void wm_xr_session_actions_update(wmXrData *xr)
return;
}
- GHOST_XrContextHandle xr_context = xr->runtime->context;
wmXrSessionState *state = &xr->runtime->session_state;
-
GHash *action_sets = state->action_sets;
if (!action_sets) {
return;
}
+
+ GHOST_XrContextHandle xr_context = xr->runtime->context;
wmXrActionSet *active_action_set = state->active_action_set;
int ret = GHOST_XrSyncActions(xr_context, active_action_set ? active_action_set->name : NULL);
@@ -687,18 +694,23 @@ void wm_xr_session_actions_update(wmXrData *xr)
}
const XrSessionSettings *settings = &xr->session_settings;
+ bContext *C = xr->runtime->bcontext;
+ wmWindowManager *wm = CTX_wm_manager(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
wmSurface *surface = (g_xr_surface && g_xr_surface->customdata) ? g_xr_surface : NULL;
- wmWindow *win = xr->runtime->session_root_win;
+ wmWindow *win = wm_xr_session_root_window_or_fallback_get(wm, xr->runtime);
if (active_action_set) {
- wm_xr_session_action_set_update(settings, xr_context, state, active_action_set, surface, win);
+ wm_xr_session_action_set_update(
+ settings, xr_context, state, active_action_set, view_layer, surface, win);
}
else {
GHashIterator *ghi_set = BLI_ghashIterator_new(action_sets);
GHASH_ITER (*ghi_set, action_sets) {
wmXrActionSet *action_set = BLI_ghashIterator_getValue(ghi_set);
if (action_set) {
- wm_xr_session_action_set_update(settings, xr_context, state, action_set, surface, win);
+ wm_xr_session_action_set_update(
+ settings, xr_context, state, action_set, view_layer, surface, win);
}
}
@@ -753,6 +765,7 @@ void wm_xr_session_controller_data_clear(unsigned int count_subaction_paths,
{
Main *bmain = CTX_data_main(C);
Sce
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list