Fix #112618: many Outliner operators crash running without a region

This could happen when e.g. overriding context with just the area.

Now add poll functions that check for an active region when running
operators that require a region.

The fix is similar to 72688791dc

Alternatively, we could have a fix similar to a8892c7264 (getting the
correct region from the area), this would require less setup by
scripters, however for some operators the usage of the region is a
little further down the line, so implementation would be a bit more
involved. Also: for some of the operators, this would have to be done in
both `invoke` and `exec` (so would be more duplicate code changes).

Pull Request: https://projects.blender.org/blender/blender/pulls/119696
This commit is contained in:
Philipp Oeser
2024-03-26 09:30:47 +01:00
committed by Philipp Oeser
parent a4f1a52a5c
commit b8bd762714
7 changed files with 45 additions and 18 deletions

View File

@@ -508,6 +508,7 @@ bool ED_operator_region_gizmo_active(bContext *C);
*/
bool ED_operator_animview_active(bContext *C);
bool ED_operator_outliner_active(bContext *C);
bool ED_operator_region_outliner_active(bContext *C);
bool ED_operator_outliner_active_no_editobject(bContext *C);
/**
* \note Will return true for file spaces in either file or asset browsing mode! See

View File

@@ -278,6 +278,20 @@ bool ED_operator_outliner_active(bContext *C)
return ed_spacetype_test(C, SPACE_OUTLINER);
}
bool ED_operator_region_outliner_active(bContext *C)
{
if (!ED_operator_outliner_active(C)) {
CTX_wm_operator_poll_msg_set(C, "Expected an active Outliner");
return false;
}
const ARegion *region = CTX_wm_region(C);
if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
CTX_wm_operator_poll_msg_set(C, "Expected an Outliner region");
return false;
}
return true;
}
bool ED_operator_outliner_active_no_editobject(bContext *C)
{
if (ed_spacetype_test(C, SPACE_OUTLINER)) {

View File

@@ -183,6 +183,17 @@ static bool collection_edit_in_active_scene_poll(bContext *C)
return true;
}
static bool collection_new_poll(bContext *C)
{
if (!ED_operator_region_outliner_active(C)) {
return false;
}
if (!collection_edit_in_active_scene_poll(C)) {
return false;
}
return true;
}
/** \} */
/* -------------------------------------------------------------------- */
@@ -268,7 +279,7 @@ void OUTLINER_OT_collection_new(wmOperatorType *ot)
/* api callbacks */
ot->exec = collection_new_exec;
ot->poll = collection_edit_in_active_scene_poll;
ot->poll = collection_new_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

View File

@@ -451,7 +451,7 @@ void OUTLINER_OT_parent_drop(wmOperatorType *ot)
/* api callbacks */
ot->invoke = parent_drop_invoke;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
@@ -609,7 +609,7 @@ void OUTLINER_OT_scene_drop(wmOperatorType *ot)
/* api callbacks */
ot->invoke = scene_drop_invoke;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
@@ -662,7 +662,7 @@ void OUTLINER_OT_material_drop(wmOperatorType *ot)
/* api callbacks */
ot->invoke = material_drop_invoke;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;

View File

@@ -296,7 +296,7 @@ void OUTLINER_OT_item_openclose(wmOperatorType *ot)
ot->invoke = outliner_item_openclose_invoke;
ot->modal = outliner_item_openclose_modal;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
RNA_def_boolean(ot->srna, "all", false, "All", "Close or open all items");
}
@@ -445,7 +445,7 @@ void OUTLINER_OT_item_rename(wmOperatorType *ot)
ot->invoke = outliner_item_rename_invoke;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* Flags. */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -596,7 +596,7 @@ void OUTLINER_OT_id_delete(wmOperatorType *ot)
ot->description = "Delete the ID under cursor";
ot->invoke = outliner_id_delete_invoke;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* Flags. */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -735,7 +735,7 @@ void OUTLINER_OT_id_remap(wmOperatorType *ot)
/* callbacks */
ot->invoke = outliner_id_remap_invoke;
ot->exec = outliner_id_remap_exec;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* Flags. */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -995,7 +995,7 @@ void OUTLINER_OT_lib_relocate(wmOperatorType *ot)
ot->description = "Relocate the library under cursor";
ot->invoke = outliner_lib_relocate_invoke;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* Flags. */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -1051,7 +1051,7 @@ void OUTLINER_OT_lib_reload(wmOperatorType *ot)
ot->description = "Reload the library under cursor";
ot->invoke = outliner_lib_reload_invoke;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* Flags. */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -1180,7 +1180,7 @@ void OUTLINER_OT_expanded_toggle(wmOperatorType *ot)
/* callbacks */
ot->exec = outliner_toggle_expanded_exec;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* no undo or registry, UI option */
}
@@ -1382,7 +1382,7 @@ void OUTLINER_OT_show_active(wmOperatorType *ot)
/* callbacks */
ot->exec = outliner_show_active_exec;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
}
/** \} */
@@ -1421,7 +1421,7 @@ void OUTLINER_OT_scroll_page(wmOperatorType *ot)
/* callbacks */
ot->exec = outliner_scroll_page_exec;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* properties */
prop = RNA_def_boolean(ot->srna, "up", false, "Up", "Scroll up one page");
@@ -1493,7 +1493,7 @@ void OUTLINER_OT_show_one_level(wmOperatorType *ot)
/* callbacks */
ot->exec = outliner_one_level_exec;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* no undo or registry, UI option */
@@ -1586,7 +1586,8 @@ void OUTLINER_OT_show_hierarchy(wmOperatorType *ot)
/* callbacks */
ot->exec = outliner_show_hierarchy_exec;
ot->poll = ED_operator_outliner_active; /* TODO: shouldn't be allowed in RNA views... */
/* TODO: shouldn't be allowed in RNA views... */
ot->poll = ED_operator_region_outliner_active;
/* no undo or registry, UI option */
}

View File

@@ -1897,7 +1897,7 @@ void OUTLINER_OT_item_activate(wmOperatorType *ot)
ot->invoke = outliner_item_activate_invoke;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -2005,7 +2005,7 @@ void OUTLINER_OT_select_box(wmOperatorType *ot)
ot->modal = WM_gesture_box_modal;
ot->cancel = WM_gesture_box_cancel;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

View File

@@ -3743,7 +3743,7 @@ void OUTLINER_OT_operation(wmOperatorType *ot)
ot->invoke = outliner_operation_invoke;
ot->poll = ED_operator_outliner_active;
ot->poll = ED_operator_region_outliner_active;
}
/** \} */