Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-327 Fix editor crash on invalid reference #328

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/editor/graph/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,18 @@ void OrchestratorGraphEdit::_synchronize_graph_with_script(bool p_apply_position

Array nodes = _script_graph->get_nodes();
for (int i = 0; i < nodes.size(); i++)
_synchronize_graph_node(_script->get_node(nodes[i]));
{
const Ref<OScriptNode> node = _script->get_node(nodes[i]);
if (!node.is_valid())
{
ERR_PRINT(vformat("Graph %s has node with id %d, but node is not found in the script metadata.",
_script_graph->get_graph_name(), nodes[i]));

_script_graph->remove_node(nodes[i]);
continue;
}
_synchronize_graph_node(node);
}

_synchronize_graph_connections_with_script();

Expand Down Expand Up @@ -585,6 +596,9 @@ void OrchestratorGraphEdit::_synchronize_graph_connections_with_script()

void OrchestratorGraphEdit::_synchronize_graph_node(Ref<OScriptNode> p_node)
{
if (!p_node.is_valid())
return;

const String node_id = itos(p_node->get_id());
if (!has_node(node_id))
{
Expand Down Expand Up @@ -1175,6 +1189,11 @@ void OrchestratorGraphEdit::_on_duplicate_nodes_request()
for (const int node_id : duplications)
{
Ref<OScriptNode> node = _script->get_node(node_id);
if (!node.is_valid())
{
ERR_PRINT("Cannot duplicate node with id " + itos(node_id));
continue;
}

// Duplicate sub-resources to handle copying pins
Ref<OScriptNode> duplicate = node->duplicate(true);
Expand Down
Loading