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

SceneTree::call_group_flags expects i64 as flag, not GroupCallFlags #185

Open
kzerot opened this issue Mar 16, 2023 · 2 comments
Open

SceneTree::call_group_flags expects i64 as flag, not GroupCallFlags #185

kzerot opened this issue Mar 16, 2023 · 2 comments
Labels
c: engine Godot classes (nodes, resources, ...) quality-of-life No new functionality, but improves ergonomics/internals status: upstream Depending on upstream fix (typically Godot)

Comments

@kzerot
Copy link

kzerot commented Mar 16, 2023

SceneTree's method call_group_flags expects i64 as a flag, not the GroupCallFlags struct. Also, "ord" field is i32, not i64.
It's working, but syntax is not very obvious:

tree.call_group_flags(GroupCallFlags::GROUP_CALL_DEFERRED.ord().into() ,"group".into(), "method".into(), &[]) 
@Bromeon Bromeon added quality-of-life No new functionality, but improves ergonomics/internals c: engine Godot classes (nodes, resources, ...) labels Mar 16, 2023
@Bromeon
Copy link
Member

Bromeon commented Dec 4, 2023

The problem is that these bitfield types are sometimes exposed as enums in the GDExtension JSON, and their parameter/return types use int.

Examples where the bitfield type is used (search bitfield:: in JSON):

There are also interesting cases that look like bitfields, but are not:

There may also be situations where a type is correctly marked as bitfield, but still used as int in APIs. Please comment if you know such cases.


I don't know how to easily detect that an enum is a bitfield, or that an int parameter/return type represents a bitfield type. There are of course some options:

  1. Manually annotating known cases.
  2. Heuristic based on method and parameter names.
    • This is going to be tough, given the above inconsistencies. Maybe also taking into account "meta": "int32" or so...
  3. Combine (1) and (2): heuristic with exceptions/additions.
  4. Implement a solution upstream, that is, fix the types in Godot's API. Might be problematic with backwards compatibility.

@Bromeon Bromeon added the status: upstream Depending on upstream fix (typically Godot) label Dec 4, 2023
@Lemiczek
Copy link
Contributor

Lemiczek commented Dec 5, 2023

To be honest, this does feel like an upstream issue that we can do very little about, without facing increasing headaches.

For the ConnectFlags example specifically, this was already called out upstream here: godotengine/godot#74829, which seems to have hit a bit of a standstill, with no further comment on breaking compatibility by making it a Bitfield<ConnectFlags>.
Maybe we come back to this if/once this is fixed for Godot 5.x? Since this is a breaking change for GDExtensions, and thus more suited for major releases?

If we were to manually annotate, I think we'd have to mark it behind a compatibility flag of sorts, since the extension API can change, and cause issues for these specific edge-cases way down the line. 🙁

We could maybe do the heuristics approach by looking at each value and seeing if it's a power of two? (There also weird edge-cases to this however, since certain flags can have duplicate values or have the value 0)

Actually we can't sinceArrayFormat (for example) despite being set as a flag/bitfield has the values 3, 7, 13, 19, etc...

I don't think we can even look for enums that end with Flags, since there are legitimate enums with that name, that go sequentially (0,1,2,3).

I really don't see a good way to solve this from our side.

Also, why are these things so inconsistent in the first place?! 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: engine Godot classes (nodes, resources, ...) quality-of-life No new functionality, but improves ergonomics/internals status: upstream Depending on upstream fix (typically Godot)
Projects
None yet
Development

No branches or pull requests

3 participants