Skip to content

Commit c60016a

Browse files
Improvements to link deletion in Graph Editor (#2816)
This changelist improves the robustness of link deletion in the MaterialX Graph Editor, including the following specific changes: - Update the pin element reference after creating a new node input in `addLink`, so that `UiPin::getInput` returns the node input rather than a stale reference to the NodeDef input. This fixes subsequent link deletion operating on the wrong element, which occasionally caused the Property Editor to continue displaying a deleted link. - Move the `ed::AcceptDeletedItem` call from `deleteLink` to its caller in `drawGraph`, so that `deleteLink` is a pure data model operation with no dependency on current ImGui Node Editor state.
1 parent 4b980fe commit c60016a

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

source/MaterialXGraphEditor/Graph.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,7 @@ void Graph::addLink(ed::PinId startPinId, ed::PinId endPinId)
24582458
{
24592459
// Get or create the actual node's input (not the NodeDef's input)
24602460
mx::InputPtr nodeInput = addNodeInput(uiDownNode, pin->getInput());
2461+
pin->setElement(nodeInput);
24612462

24622463
// Update value to be empty
24632464
if (uiDownNode->getNode() && uiDownNode->getNode()->getType() == mx::SURFACE_SHADER_TYPE_STRING)
@@ -2700,24 +2701,20 @@ void Graph::deleteLinkInfo(int startAttr, int endAttr)
27002701

27012702
void Graph::deleteLink(ed::LinkId deletedLinkId)
27022703
{
2703-
// If you agree that link can be deleted, accept deletion.
2704-
if (ed::AcceptDeletedItem())
2705-
{
2706-
_renderer->setMaterialCompilation(true);
2707-
_frameCount = ImGui::GetFrameCount();
2708-
int link_id = int(deletedLinkId.Get());
2709-
2710-
// Then remove link from your data.
2711-
int pos = findLinkPosition(link_id);
2712-
if (pos < 0)
2713-
{
2714-
return;
2715-
}
2704+
_renderer->setMaterialCompilation(true);
2705+
_frameCount = ImGui::GetFrameCount();
2706+
int link_id = int(deletedLinkId.Get());
27162707

2717-
Link currLink = _state.links[pos];
2718-
deleteLinkInfo(currLink._startAttr, currLink._endAttr);
2719-
_state.links.erase(_state.links.begin() + pos);
2708+
// Remove link from the current link vector.
2709+
int pos = findLinkPosition(link_id);
2710+
if (pos < 0)
2711+
{
2712+
return;
27202713
}
2714+
2715+
Link currLink = _state.links[pos];
2716+
deleteLinkInfo(currLink._startAttr, currLink._endAttr);
2717+
_state.links.erase(_state.links.begin() + pos);
27212718
}
27222719

27232720
void Graph::deleteNode(UiNodePtr node)
@@ -4458,7 +4455,10 @@ void Graph::drawGraph(ImVec2 mousePos)
44584455
{
44594456
if (!readOnly())
44604457
{
4461-
deleteLink(deletedLinkId);
4458+
if (ed::AcceptDeletedItem())
4459+
{
4460+
deleteLink(deletedLinkId);
4461+
}
44624462
}
44634463
else
44644464
{

0 commit comments

Comments
 (0)