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

Fix some DEFVALs to use the right type #84906

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

raulsntos
Copy link
Member

Change some default parameter values to use the right type, this affects how they are exposed in extension_api.json as well as the generated C# bindings.

  • For StringNames, DEFVAL(StringName()) will be written as &"" as opposed to "" (which is used for String).
  • For Variant, DEFVAL(Variant()) will be written as null. DEFVAL(Variant::NIL) is incorrect since that's an enum and will result in 0 as the written value. This change probably breaks behavior compatibility so I'm adding the label.

@akien-mga
Copy link
Member

For the remaining two extension validation errors, you need to add compatibility methods so that the old hashes are preserved:

Validate extension JSON: Error: Hash changed for 'classes/AnimationPlayer/methods/play', from 846788DD to DC6A3489. This means that the function has changed and no compatibility function was provided.
Validate extension JSON: Error: Hash changed for 'classes/AnimationPlayer/methods/play_backwards', from A6228DE1 to E7E6D578. This means that the function has changed and no compatibility function was provided.

@raulsntos
Copy link
Member Author

I find it odd that it's complaining about a hash change only in those methods though, I only changed the default value of a StringName parameter like in all the other methods.

@AThousandShips
Copy link
Member

Could be because all other methods have a register hash in core/extension/gdextension_compat_hashes.cpp unsure but it's a pattern

@akien-mga
Copy link
Member

akien-mga commented Nov 15, 2023

I find it odd that it's complaining about a hash change only in those methods though, I only changed the default value of a StringName parameter like in all the other methods.

Yeah that's weird. Maybe the check aborts too early with the error and doesn't list the other missing hashes. If so fixing those two might unlock the next batch of errors? CC @RedworkDE

Edit: Or what AThousandShips wrote.

@raulsntos raulsntos force-pushed the fix-some-defvals branch 3 times, most recently from d8e6168 to 9095b3f Compare November 15, 2023 17:03
@akien-mga
Copy link
Member

akien-mga commented Nov 16, 2023

Could be because all other methods have a register hash in core/extension/gdextension_compat_hashes.cpp unsure but it's a pattern

I think this may actually be a significant issue with the compat hashes approach, as we may not do proper validation that the new hashes do match the methods we currently provide, and thus we might be missing errors.

The hashes for all methods that changed default argument values here are probably wrong in that file and would need to be fixed, or those compat hashes would be pointing at non-existing hashes.

And thus all methods modified here possibly need compat methods registered anyway, even if the checks are not complaining.

CC @dsnopek

@dsnopek
Copy link
Contributor

dsnopek commented Nov 16, 2023

I just posted PR #84973 which aims to expose issues where the mapped hash from core/extension/gdextension_compat_hashes.cpp is no longer valid. I didn't test it with the changes from this PR (I only did an artificial test where I added an invalid hash on purpose) - it'd be great to see what it turns up here.

@akien-mga
Copy link
Member

Would be good to rebase this PR on #84973 so we can confirm whether that's the problem and if it will highlight it properly.

Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

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

This seems fine to me!

Assuming I'm understanding correctly, the only "true" compatibility breakage is from where a Variant default changes from 0 to null, which is only on CodeEdit::add_code_completion_option(). That seems acceptable to me.

@dsnopek dsnopek modified the milestones: 4.x, 4.3 Dec 1, 2023
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be moved to the 4.2 file now that it exists

@akien-mga
Copy link
Member

Nothing urgent, but would be good to revisit this sooner than later for the 4.3 cycle.

@raulsntos raulsntos force-pushed the fix-some-defvals branch 2 times, most recently from 2c36e2c to 2384c03 Compare January 30, 2024 20:09
@AThousandShips
Copy link
Member

@dsnopek the compat hashes are all out of date, how to update them/add them?

@akien-mga
Copy link
Member

@dsnopek the compat hashes are all out of date, how to update them/add them?

I don't know if David had a handy script to do this, but I suppose the manual way would be to compile this PR, generate the extension API, and copy paste the new hashes from that JSON in place of the ones in gdextension_compat_hashes.cpp (provided they are indeed still the same method / compatible).

@dsnopek
Copy link
Contributor

dsnopek commented Feb 10, 2024

While I used a script to generate them originally, I don't have a script to update them.

How many hashes in gdextension_compat_hashes.cpp does this affect?

The mapping in gdextension_compat_hashes.cpp was added for an exceptional situation (we fixed a bug in the way the hashes are calculated) and so they really shouldn't need to be updated except in exceptional circumstances - normally, we can just add compatibility methods. This PR could be an exceptional circumstance that qualifies.

Although, looking back at this now: why can't we just add normal compatibility methods for this?

In the cases where the only thing that changes is the DEFVAL() in the ClassDB::bind_method() (as opposed to an actual signature change to the method), we probably don't even need to make a new method, we might be able to just call ClassDB::bind_compatibility_method() using the same function pointer but with the old DEFVAL()'s.

- Use `StringName()` in DEFVAL for StringNames.
- Use `Variant()` in DEFVAL for Variants.
@akien-mga akien-mga merged commit 3ce9ae7 into godotengine:master Feb 23, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@raulsntos raulsntos deleted the fix-some-defvals branch February 23, 2024 17:29
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.

4 participants