-
-
Notifications
You must be signed in to change notification settings - Fork 22.8k
PackedScene: Avoid saving signal connections twice #100965
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
base: master
Are you sure you want to change the base?
Changes from all commits
2a31298
1f93850
5feeb11
7f371b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,11 @@ TEST_CASE("[PackedScene] Signals Preserved when Packing Scene") { | |
main_scene_root->add_child(sub_scene_root); | ||
sub_scene_root->set_owner(main_scene_root); | ||
|
||
main_scene_root->_set_scene_connection_id(123); | ||
sub_node->_set_scene_connection_id(123); | ||
sub_scene_root->_set_scene_connection_id(456); | ||
sub_scene_node->_set_scene_connection_id(456); | ||
|
||
SUBCASE("Signals that should be saved") { | ||
int main_flags = Object::CONNECT_PERSIST; | ||
// sub node to a node in main scene | ||
|
@@ -95,16 +100,24 @@ TEST_CASE("[PackedScene] Signals Preserved when Packing Scene") { | |
CHECK_EQ(state->get_connection_count(), 3); | ||
} | ||
|
||
/* | ||
// FIXME: This subcase requires GH-48064 to be fixed. | ||
/* TODO needs fixed | ||
Comment on lines
-99
to
+103
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. Closing the issue does not fix this case? 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. I started working on so 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. The tests were for a solution that used |
||
SUBCASE("Signals that should not be saved") { | ||
int subscene_flags = Object::CONNECT_PERSIST | Object::CONNECT_INHERITED; | ||
Callable p_callable; | ||
// subscene node to itself | ||
p_callable = callable_mp(sub_scene_node, &Node::is_ready); | ||
sub_scene_node->connect("ready", callable_mp(sub_scene_node, &Node::is_ready), subscene_flags); | ||
sub_scene_root->set_connection_id("ready", p_callable, 456); | ||
// subscene node to subscene root | ||
sub_scene_node->connect("ready", callable_mp(sub_scene_root, &Node::is_ready), subscene_flags); | ||
p_callable = callable_mp(sub_scene_root, &Node::is_ready); | ||
sub_scene_root->connect("ready", p_callable , subscene_flags); | ||
sub_scene_root->set_connection_id("ready", p_callable, 456); | ||
//subscene root to subscene root (connected within sub scene) | ||
sub_scene_root->connect("ready", callable_mp(sub_scene_root, &Node::is_ready), subscene_flags); | ||
p_callable = callable_mp(sub_scene_root, &Node::is_ready); | ||
sub_scene_root->connect("ready", p_callable, subscene_flags); | ||
sub_scene_root->set_connection_id("ready", p_callable, 456); | ||
// Pack the scene. | ||
Ref<PackedScene> packed_scene; | ||
|
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.
worth mentioning that this code seems to solve the issue for the editor since there's never an error when saving a scene in the editor. When packing a scene it checks to see if the connection was already saved, and if it was, not pack it again.
When calling
pack
from code, however, this doesn't work as the connections are saved multiple times. I think scene packing was originally just meant to be used by the editor, not in code, which could be why this bug was not caught when this code was written. I admittedly did not figure out exactly why this block wasn't working despite spending a couple days trying to debug it.However I've been using a custom build of 4.4 with the changes in this PR almost daily for about a month now without any problems.