-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Disconnect graph connections when ports are removed in visual shaders #80312
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -440,6 +440,10 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool | |||||||||||
custom_node->_set_initialized(true); | ||||||||||||
} | ||||||||||||
|
||||||||||||
if (!p_just_update) { | ||||||||||||
vsnode->connect("node_ports_removed", callable_mp(editor, &VisualShaderEditor::_node_ports_removed).bind(p_id)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
// Create graph node. | ||||||||||||
GraphNode *node = memnew(GraphNode); | ||||||||||||
graph->add_child(node); | ||||||||||||
|
@@ -2661,6 +2665,27 @@ void VisualShaderEditor::_port_edited(const StringName &p_property, const Varian | |||||||||||
undo_redo->commit_action(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
void VisualShaderEditor::_node_ports_removed(int p_id) { | ||||||||||||
VisualShader::Type shader_type = visual_shader->get_shader_type(); | ||||||||||||
Ref<VisualShaderNode> node = visual_shader->get_node(shader_type, p_id); | ||||||||||||
if (!node.is_valid()) | ||||||||||||
return; | ||||||||||||
Comment on lines
+2671
to
+2672
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Code style, we use brackets always for if-statements |
||||||||||||
const int inputs = node->get_input_port_count(), | ||||||||||||
outputs = node->get_output_port_count(); | ||||||||||||
Comment on lines
+2673
to
+2674
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Readability |
||||||||||||
List<VisualShader::Connection> conns; | ||||||||||||
visual_shader->get_node_connections(shader_type, &conns); | ||||||||||||
for (const VisualShader::Connection &c : conns) { | ||||||||||||
if (unlikely(c.from_node == p_id && c.from_port >= outputs)) { | ||||||||||||
graph_plugin->disconnect_nodes(shader_type, c.from_node, c.from_port, c.to_node, c.to_port); | ||||||||||||
visual_shader->disconnect_nodes(shader_type, c.from_node, c.from_port, c.to_node, c.to_port); | ||||||||||||
|
||||||||||||
} else if (unlikely(c.to_node == p_id && c.to_port >= inputs)) { | ||||||||||||
graph_plugin->disconnect_nodes(shader_type, c.from_node, c.from_port, c.to_node, c.to_port); | ||||||||||||
visual_shader->disconnect_nodes(shader_type, c.from_node, c.from_port, c.to_node, c.to_port); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, int p_port) { | ||||||||||||
VisualShader::Type type = get_current_shader_type(); | ||||||||||||
Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, p_node); | ||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should try to use CONNECT_DEFERRED flag to prevent that crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give it a shot thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did fix the crash! I have another issue though: the op_type change and the connections removal are not in the same action, which means that hitting ctrl+z only recreates the connections without reverting to the previous op_type. As far as I can understand, handling removed ports should be done in
_property_changed
function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then unify it to a single action, (
CONNECT_DEFERRED
will not be needed in that case), remove create_action/commit_action from the_node_ports_removed
and uses the same action as usual just call it before thecommit_action
of the op_type change function has been called.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's what I was proposing: the
commit_action
gets called inVisualShaderNodePluginDefaultEditor::_property_changed
so all I need to do is check for invalid connections there.It means that invalid connections will be checked everytime a property gets called whether this property has an impact on the number of ports or not. On the other hand, it also means that no matter what happens in the future invalid connections will always be removed as they should be