-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Fix script used as type gone too early (3.2) #43049
Conversation
Release builds fail with:
|
0359c66
to
f7463ce
Compare
I'm still researching what is going on (still pretty new to Godot internals) but I think this is causing problems if I try to use duplicate with a GDScript class only meant to hold data. I am using the Resource::duplicate() to make copies at points and I am getting an unhandled exception in Object::set. I've applied this PR on top of a fresh copy of 3.2.4 beta 1 BTW. |
@ChainedLupine, a minimal reproduction project would be appreciated. |
Here you go! |
f7463ce
to
709e7b2
Compare
I've cherry-picked a fixup by @vnen that was needed. @ChainedLupine, I don't have time now to test your project. Could you test this PR again on it? |
I just re-tested with @vnen's fixup and it still does it. For the record, testing under Windows 10 with VS2019 compiler (crash happens in either debug/release). |
Just to verify I reverted to 2e073ec and I'm not getting the crash. It's definitely something in this PR which is causing a problem with duplicate(). |
I can confirm that with the latest Haven't tried with the PR yet but this needs to be addressed before merging. |
I've narrowed it down to the changes in variant.cpp. For some reason, when Object::set_script occurs in the cloned Resource, the script_instance seems to refer to a ScriptInstance with no implementation. So when script_instance::set occurs, there's an unhandled exception. |
I've been investigating this. The same happens in 4.0, where The problem is that if a That is happening to the I can think of two ways to fix this:
I'd like to hear @vnen's opinion again. I'm not sure if option 2) would have unintended side effects. We could just do 1) and consider an error assigning a not yet referenced |
@ChainedLupine, by the way, thanks for the test project and your insights! |
Aha! That explains why the self reference is hollowed out after it finishes running the initializer during set_script, because it's pointing to just the abstract class and not a real object. Now I understand what is going on. @RandomShaper Thanks for figuring it out, I am so glad I could help! |
To recap on the situation:
|
709e7b2
to
1e9a774
Compare
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.
Let's merge to fix the identified regressions, and open a new bug report to track the regression already present in the master
branch and which this PR is exposing to 3.2.
Thanks! |
Following up on what I explained in #42323, it seems that the problem with
Variant
'sObject *
constructor was very needed. The only thing that was preventing me from doing it is that GDScript was leveraging the wrong behavior. However, it seems that @vnen already fixed that.I've cherry-picked the commit that removes that naughtiness from GDScript and the definitive fix for
Variant
has become possible.Variant
will now manage the lifetime of aReference
nicely even if it's assigned via theObject *
constructor. As I explained in the mentioned PR, without that fix, two incompatible reference counting mechanisms were being used simultaneously, which was nothing else than summoning the most terrible forces in a cold and stormy night.NOTE: 4.0 already gets this right.
Fixes #43042.
UPDATE: Fixes #43166.