Fix: Viewer node crashes when the editor is pinned and has no Object ID #107737

Merged
Lukas Tönne merged 3 commits from LukasTonne/blender:fix_viewer_node_in_pinned_editor into main 2023-05-08 14:52:14 +02:00
1 changed files with 27 additions and 25 deletions
Showing only changes of commit ad2ef73160 - Show all commits

View File

@ -26,34 +26,36 @@ static void viewer_path_for_geometry_node(const SpaceNode &snode,
{
BKE_viewer_path_init(&r_dst);
Object *ob = reinterpret_cast<Object *>(snode.id);
IDViewerPathElem *id_elem = BKE_viewer_path_elem_new_id();
id_elem->id = &ob->id;
BLI_addtail(&r_dst.path, id_elem);
if (snode.id != nullptr && GS(snode.id->name) == ID_OB) {

Better check for this in the caller and only add an assert here. It's not possible to build a viewer path for a geometry node when parts of the context path (including the object and modifier) are missing.

Better check for this in the caller and only add an assert here. It's not possible to build a viewer path for a geometry node when parts of the context path (including the object and modifier) are missing.
Object *ob = reinterpret_cast<Object *>(snode.id);
IDViewerPathElem *id_elem = BKE_viewer_path_elem_new_id();
id_elem->id = &ob->id;
BLI_addtail(&r_dst.path, id_elem);
NodesModifierData *modifier = nullptr;
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
if (md->type != eModifierType_Nodes) {
continue;
NodesModifierData *modifier = nullptr;
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
if (md->type != eModifierType_Nodes) {
continue;
}
NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(md);
if (nmd->node_group != snode.nodetree) {
continue;
}
if (snode.flag & SNODE_PIN) {
/* If the node group is pinned, use the first matching modifier. This can be improved by
* storing the modifier name in the node editor when the context is pinned. */
modifier = nmd;
break;
}
if (md->flag & eModifierFlag_Active) {
modifier = nmd;
}
}
NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(md);
if (nmd->node_group != snode.nodetree) {
continue;
if (modifier != nullptr) {
ModifierViewerPathElem *modifier_elem = BKE_viewer_path_elem_new_modifier();
modifier_elem->modifier_name = BLI_strdup(modifier->modifier.name);
BLI_addtail(&r_dst.path, modifier_elem);
}
if (snode.flag & SNODE_PIN) {
/* If the node group is pinned, use the first matching modifier. This can be improved by
* storing the modifier name in the node editor when the context is pinned. */
modifier = nmd;
break;
}
if (md->flag & eModifierFlag_Active) {
modifier = nmd;
}
}
if (modifier != nullptr) {
ModifierViewerPathElem *modifier_elem = BKE_viewer_path_elem_new_modifier();
modifier_elem->modifier_name = BLI_strdup(modifier->modifier.name);
BLI_addtail(&r_dst.path, modifier_elem);
}
Vector<const bNodeTreePath *, 16> tree_path = snode.treepath;