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

Make InstancePlaceholders in charge of resolving node references in instances #90306

Merged
merged 1 commit into from
May 28, 2024

Conversation

TheOrioli
Copy link
Contributor

@TheOrioli TheOrioli commented Apr 6, 2024

This is my attempt at resolving #88662

From what I could figure out with my limited understanding of the codebase, the issue seems deeper than just the suspected PR #83343

I have created an even bigger repro project that tries to really abuse node properties, arrays and their resolutions during the instantiation process.

PlaceholderInstanceRepro.zip

This project not only fails in versions 4.3-dev.X, but also in 4.2.1, where arrays of external and mixed node references hit the error here

ERR_CONTINUE(!valid);

I am not nearly comfortable enough with the system to truly say that this is the correct solution, but I hope it can through reviews and discussion serve as a base of finding one.

Bugsquad edit:

scene/main/instance_placeholder.h Outdated Show resolved Hide resolved
scene/main/instance_placeholder.h Outdated Show resolved Hide resolved
scene/main/instance_placeholder.cpp Outdated Show resolved Hide resolved
scene/main/instance_placeholder.cpp Outdated Show resolved Hide resolved
scene/main/instance_placeholder.cpp Outdated Show resolved Hide resolved
scene/main/instance_placeholder.cpp Outdated Show resolved Hide resolved
scene/main/instance_placeholder.cpp Outdated Show resolved Hide resolved
scene/main/instance_placeholder.cpp Outdated Show resolved Hide resolved
scene/main/instance_placeholder.cpp Outdated Show resolved Hide resolved
scene/resources/packed_scene.cpp Outdated Show resolved Hide resolved
@TheOrioli
Copy link
Contributor Author

@AThousandShips appreciate the review 🙌

I would just like to try and write some actual tests as well, seems there are no tests for instance placeholders and it might be cool to get some coverage on all this new code.

@AThousandShips
Copy link
Member

Sounds great!

@TheOrioli
Copy link
Contributor Author

@AThousandShips I've added some tests for the new behavior. There are still a couple of test cases that might be good to cover, specifically concerning properties that should contain Node's but their NodePath is overridden with the same value, so they reference an internal node after creation. This happens quite often now in the editor, since the editor seems to like setting the same value on the properties which is then stored as override in the PackedScene resource, as seen here:
image

But it would be good to get some eyes with testing experience to tell me if my current approach is actually good or not 🙌

@AThousandShips
Copy link
Member

I'll try take a look soon

@TheOrioli
Copy link
Contributor Author

There we go 😁 bda230e is a test that will fail on the current master branch, while it works with this PR. I will add a few additional tests in the same vein later today 💪

Is there an official/best practice way of creating and deleting temporary files created during tests?

@AThousandShips
Copy link
Member

I'm not sure if there's any good practice for the creation or deletion, I'd suggest checking some of the other tests, like core/io, should be something in there

Code looks good I believe, wasn't able to do a functional evaluation at the moment though

@TheOrioli
Copy link
Contributor Author

Seems like the core/io tests write into the OS cache directory. I've changed my tests to do the same. I am surprised there doesn't seem to be an OS singleton method to get the temporary directory of the filesystem, but that is outside the scope of this PR.

I don't know where more to take this, so I would say it's as ready as it will get until further reviews are done 👍

@TheOrioli
Copy link
Contributor Author

Merged the latest master into the branch 👍

@AThousandShips
Copy link
Member

In the future please use rebasing to update your branch, see here

Copy link
Member

@SaracenOne SaracenOne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! This mostly looks good, but could you examine one issue I raised in regards to the editor losing direct node references. Also could you squash this PR into a single commit? This is generally the preferred way to merge PRs in Godot.

scene/resources/packed_scene.cpp Outdated Show resolved Hide resolved
@TheOrioli
Copy link
Contributor Author

@SaracenOne thank you for the review. Added the fix, squashed into one commit, rebased on master.

Copy link
Member

@SaracenOne SaracenOne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@akien-mga akien-mga requested a review from KoBeWi May 23, 2024 06:53
scene/main/instance_placeholder.cpp Outdated Show resolved Hide resolved
scene/main/instance_placeholder.cpp Outdated Show resolved Hide resolved
scene/main/instance_placeholder.h Outdated Show resolved Hide resolved
scene/main/instance_placeholder.cpp Outdated Show resolved Hide resolved
tests/scene/test_instance_placeholder.h Outdated Show resolved Hide resolved
tests/scene/test_instance_placeholder.h Outdated Show resolved Hide resolved
Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not that familiar with InstancePlaceholder, but the code seems fine.

Is there an official/best practice way of creating and deleting temporary files created during tests?

The official practice seems to be polluting a "cache" directory 🙃
#92097

@TheOrioli
Copy link
Contributor Author

TheOrioli commented May 24, 2024

@KoBeWi

I'm not that familiar with InstancePlaceholder, but the code seems fine.

Is there an official/best practice way of creating and deleting temporary files created during tests?

The official practice seems to be polluting a "cache" directory 🙃 #92097

Thank for the review, I'll remove the comment and push a new version.

Concerning #92097 I noticed OS seems to lack a temporary directory method, so I'm thinking about making a PR later adding support for it and seeing what happens to the tests if they use that instead.

@KoBeWi
Copy link
Member

KoBeWi commented May 24, 2024

As I noted in the issue, it'd be fine if there was a test-specific helper method that returns a fixed sub-directory, so at least the files are isolated.

@akien-mga akien-mga merged commit 5b2dc8a into godotengine:master May 28, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in InstancePlaceholder behavior, instanced scene missing Node property values
5 participants