Skip to content

Commit

Permalink
Fixed null check in Graph::propertyEditor (#1601)
Browse files Browse the repository at this point in the history
  • Loading branch information
eytienne authored Nov 21, 2023
1 parent 30a446e commit 60c8a59
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions source/MaterialXGraphEditor/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ mx::DocumentPtr Graph::loadDocument(mx::FilePath filename)
std::cerr << "*** Validation warnings for " << filename.asString() << " ***" << std::endl;
std::cerr << message << std::endl;
}

// Cache the currently loaded file
_materialFilename = filename;
}
Expand Down Expand Up @@ -2102,11 +2102,11 @@ mx::InputPtr Graph::findInput(mx::InputPtr nodeInput, const std::string& name)
{
if (_isNodeGraph)
{
for (UiNodePtr node : _graphNodes)
for (UiNodePtr uiNode : _graphNodes)
{
if (node->getNode())
if (uiNode->getNode())
{
for (mx::InputPtr input : node->getNode()->getActiveInputs())
for (mx::InputPtr input : uiNode->getNode()->getActiveInputs())
{
if (input->getInterfaceInput())
{
Expand Down Expand Up @@ -2547,7 +2547,7 @@ void Graph::addLink(ed::PinId startPinId, ed::PinId endPinId)
return;
}

// Perform type check
// Perform type check
bool typesMatch = (outputPin->_type == inputPin->_type);
if (!typesMatch)
{
Expand Down Expand Up @@ -3093,7 +3093,7 @@ void Graph::loadGraphFromFile(bool prompt)
_fileDialog.open();
}
else
{
{
_graphDoc = loadDocument(_materialFilename);

// Rebuild the UI
Expand All @@ -3104,7 +3104,7 @@ void Graph::loadGraphFromFile(bool prompt)

_renderer->setDocument(_graphDoc);
_renderer->updateMaterials(nullptr);
}
}
}

void Graph::saveGraphToFile()
Expand Down Expand Up @@ -3241,22 +3241,22 @@ void Graph::graphButtons()

// Create two windows using splitter
float paneWidth = (leftPaneWidth - 2.0f);

float aspectRatio = _renderer->getPixelRatio();
ImVec2 screenSize = ImVec2(paneWidth, paneWidth / aspectRatio);

ImVec2 mousePos = ImGui::GetMousePos();
ImVec2 tempWindowPos = ImGui::GetCursorPos();
bool cursorInRenderView = mousePos.x > tempWindowPos.x && mousePos.x < (tempWindowPos.x + screenSize.x) &&
mousePos.y > tempWindowPos.y && mousePos.y < (tempWindowPos.y + screenSize.y);

ImGuiWindowFlags windowFlags = 0;

if (cursorInRenderView)
{
windowFlags |= ImGuiWindowFlags_NoScrollWithMouse;
}

ImGui::BeginChild("Selection", ImVec2(paneWidth, 0), false, windowFlags);
ImVec2 windowPos = ImGui::GetWindowPos();

Expand Down Expand Up @@ -3306,16 +3306,16 @@ void Graph::propertyEditor()
std::string name = _currUiNode->getNode()->getParent()->createValidChildName(temp);

std::vector<UiNodePtr> downstreamNodes = _currUiNode->getOutputConnections();
for (UiNodePtr nodes : downstreamNodes)
for (UiNodePtr uiNode : downstreamNodes)
{
if (nodes->getInput() == nullptr)
if (!uiNode->getInput() && uiNode->getNode())
{
for (mx::InputPtr input : nodes->getNode()->getActiveInputs())
for (mx::InputPtr input : uiNode->getNode()->getActiveInputs())
{
if (input->getConnectedNode() == _currUiNode->getNode())
{
_currUiNode->getNode()->setName(name);
nodes->getNode()->setConnectedNode(input->getName(), _currUiNode->getNode());
uiNode->getNode()->setConnectedNode(input->getName(), _currUiNode->getNode());
}
}
}
Expand All @@ -3330,13 +3330,13 @@ void Graph::propertyEditor()
{
std::string name = _currUiNode->getInput()->getParent()->createValidChildName(temp);
std::vector<UiNodePtr> downstreamNodes = _currUiNode->getOutputConnections();
for (UiNodePtr nodes : downstreamNodes)
for (UiNodePtr uiNode : downstreamNodes)
{
if (nodes->getInput() == nullptr)
if (uiNode->getInput() == nullptr)
{
if (nodes->getNode())
if (uiNode->getNode())
{
for (mx::InputPtr input : nodes->getNode()->getActiveInputs())
for (mx::InputPtr input : uiNode->getNode()->getActiveInputs())
{
if (input->getInterfaceInput() == _currUiNode->getInput())
{
Expand All @@ -3349,7 +3349,7 @@ void Graph::propertyEditor()
}
else
{
nodes->getOutput()->setConnectedNode(_currUiNode->getNode());
uiNode->getOutput()->setConnectedNode(_currUiNode->getNode());
}
}
}
Expand Down Expand Up @@ -3726,7 +3726,6 @@ void Graph::addNodePopup(bool cursor)
}
}


ImGui::EndMenu();
}
}
Expand Down Expand Up @@ -3894,7 +3893,6 @@ void Graph::handleRenderViewInputs()
{
_renderer->setScrollEvent(scrollAmt);
}

}

void Graph::drawGraph(ImVec2 mousePos)
Expand Down

0 comments on commit 60c8a59

Please sign in to comment.