-
-
Notifications
You must be signed in to change notification settings - Fork 576
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 CallableCustom comparison function handling #1612
base: master
Are you sure you want to change the base?
Conversation
In the GDExtension API the CallableCustom interface defines the `hash_func`, `equal_func`, and `less_than_func` methods as optional. However, in godot-cpp a custom handler was always provided to Godot. This custom provider then failed if both Callables had specified nullptr as their equal or less_than_equal comparison function. This commit fixes this, and only sets the custom handler, when a custom handler is actually specified by the developer. Also, if the hash() function returns 0, then no hash function is provided to Godot, so it falls back to its default hash function.
Thanks! However, I don't personally like this change. In Godot itself, child classes of I understand that the GDExtension interface allows those callbacks to be optional, however, that doesn't mean that godot-cpp needs to allow that. godot-cpp attempts to adapt the GDExtension interface in a way that is in accordance with its design goals - other GDExtension bindings may approach this differently. |
My main concern is that this makes Godot harder to use: different languages may have different implementation requirements for custom Callables. Also, I don't understand why it should be required for engine users to implement their own comparison and hash operations, when there is already a suitable default implementation inside the engine. What is even worse, you can specify nullptr for both the equal and less operators in custom Callables implemented in godot-cpp, and things will work, as long as you don't try to connect 2 of such callables to the same signal. (This is how we encountered this problem in some special case during beta testing - it went completely unnoticed during development.) In my opinion, there are multiple options to have a consistent API both in-engine and out:
What do you think? |
Changing the API of Please feel free to make a Godot issue or PR to start a discussion with the core team.
However, I don't personally see any reason to change the GDExtension interface. I think having those callbacks optional within the GDExtension interface was the right decision, because it potentially makes it a little easier to create new GDExtension bindings. The GDExtension interface != godot-cpp, and it's only godot-cpp that has the goal of providing the same API as Godot modules (with the same limitations), so I don't think we should limit the GDExtension interface to only the things that godot-cpp wants to support. This isn't the only thing we've added to the GDExtension interface to make life easier for other bindings that godot-cpp chooses not to use. |
In the GDExtension API the CallableCustom interface defines the
hash_func
,equal_func
, andless_than_func
methods as optional.However, in godot-cpp a custom handler was always provided to Godot. This custom provider then failed if both Callables had specified nullptr as their equal or less_than_equal comparison function.
This commit fixes this, and only sets the custom handler, when a custom handler is actually specified by the developer.
Also, if the hash() function returns 0, then no hash function is provided to Godot, so it falls back to its default hash function.
This issue was originally discovered in Godot 4.3, so it might be a good idea to cherry-pick it to that branch.
Developed by Migeran