Fix #119384: Outliner crash extend mode toggle on objects sharing data #119416

Closed
Philipp Oeser wants to merge 3 commits from lichtwerk/blender:119384 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 30 additions and 3 deletions

View File

@ -2142,6 +2142,33 @@ static void outliner_buttons(const bContext *C,
}
}
static bool outliner_is_object_data_shared_in_mode(TreeViewContext *tvc,
const Object *ob,
const Object *ob_active)
{
if (ob->data == ob_active->data) {
return true;
}
if (static_cast<const ID *>(ob->data)->us <= 1) {
return false;
}
/* If the ID has multiple users, also check if any object using it is in the same mode as the
lichtwerk marked this conversation as resolved
Review

It's easy to confuse ob and object. Better name this iter_object or something clearer. Also, const.

It's easy to confuse `ob` and `object`. Better name this `iter_object` or something clearer. Also, `const`.
* active object. */
lichtwerk marked this conversation as resolved
Review

Return true in this case rather than changing a boolean, then return false at the end.

Return true in this case rather than changing a boolean, then return false at the end.
ObjectsInModeParams params = {0};
params.object_mode = ob_active->mode;
Vector<Object *> objects_in_mode = BKE_view_layer_array_from_objects_in_mode_params(
tvc->scene, tvc->view_layer, nullptr, &params);
for (const Object *object_iter : objects_in_mode) {
if (object_iter->data == ob->data) {
return true;
}
}
return false;
}
static void outliner_mode_toggle_fn(bContext *C, void *tselem_poin, void * /*arg2*/)
{
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
@ -2157,8 +2184,8 @@ static void outliner_mode_toggle_fn(bContext *C, void *tselem_poin, void * /*arg
/* Check that the item is actually an object. */
BLI_assert(tselem->id != nullptr && GS(tselem->id->name) == ID_OB);
Object *ob = (Object *)tselem->id;
const bool object_data_shared = (ob->data == tvc.obact->data);
const bool object_data_shared = outliner_is_object_data_shared_in_mode(
&tvc, (Object *)tselem->id, tvc.obact);
wmWindow *win = CTX_wm_window(C);
const bool do_extend = (win->eventstate->modifier & KM_CTRL) && !object_data_shared;
@ -2199,7 +2226,7 @@ static void outliner_draw_mode_column_toggle(uiBlock *block,
draw_active_icon = false;
}
const bool object_data_shared = (ob->data == ob_active->data);
const bool object_data_shared = outliner_is_object_data_shared_in_mode(tvc, ob, ob_active);
draw_active_icon = draw_active_icon || object_data_shared;
int icon;