Fix #111713: Nodes crash when library overriding #111782

Merged
Lukas Tönne merged 1 commits from LukasTonne/blender:fix-root-panel-rna-crash2 into main 2023-09-01 12:39:58 +02:00
3 changed files with 16 additions and 7 deletions

View File

@ -1205,7 +1205,7 @@ bNodeTreeInterfaceItem *bNodeTreeInterface::insert_item_copy(const bNodeTreeInte
bool bNodeTreeInterface::remove_item(bNodeTreeInterfaceItem &item, bool move_content_to_parent)
{
bNodeTreeInterfacePanel *parent = this->find_item_parent(item);
bNodeTreeInterfacePanel *parent = this->find_item_parent(item, true);
if (parent == nullptr) {
return false;
}

View File

@ -246,7 +246,10 @@ typedef struct bNodeTreeInterface {
/* const_cast to avoid a const version of #find_parent_recursive. */
const bNodeTreeInterfacePanel *parent =
const_cast<bNodeTreeInterfacePanel &>(root_panel).find_parent_recursive(item);
BLI_assert(parent != nullptr);
if (parent == nullptr || parent == &root_panel) {
/* Panel is the root panel. */
return 0;
}
return parent->item_position(item);
}
/**
@ -274,11 +277,19 @@ typedef struct bNodeTreeInterface {
}
/**
* Find the panel containing the item.
* \param include_root: Allow #root_panel as a return value,
* otherwise return nullptr for root items.
* \return Parent panel containing the item.
*/
bNodeTreeInterfacePanel *find_item_parent(const bNodeTreeInterfaceItem &item)
bNodeTreeInterfacePanel *find_item_parent(const bNodeTreeInterfaceItem &item,
bool include_root = false)
{
return root_panel.find_parent_recursive(item);
bNodeTreeInterfacePanel *parent = root_panel.find_parent_recursive(item);
/* Return nullptr instead the root panel. */
if (!include_root && parent == &root_panel) {
return nullptr;
}
return parent;
}
/**

View File

@ -554,9 +554,6 @@ static bNodeTreeInterfaceItem *rna_NodeTreeInterfaceItems_copy(ID *id,
{
/* Copy to same parent as the item. */
bNodeTreeInterfacePanel *parent = interface->find_item_parent(*item);
if (parent == nullptr) {
return nullptr;
}
return rna_NodeTreeInterfaceItems_copy_to_parent(id, interface, bmain, reports, item, parent);
}
@ -850,6 +847,7 @@ static void rna_def_node_interface_item(BlenderRNA *brna)
RNA_def_property_pointer_funcs(
prop, "rna_NodeTreeInterfaceItem_parent_get", nullptr, nullptr, nullptr);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
RNA_def_property_ui_text(prop, "Parent", "Panel that contains the item");
prop = RNA_def_property(srna, "position", PROP_INT, PROP_NONE);