Skip to content

Commit

Permalink
Fix CallableCustom comparison function handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kisg committed Oct 4, 2024
1 parent 6facde3 commit 4d6f40a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/variant/callable_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ Callable::Callable(CallableCustom *p_callable_custom) {
info.call_func = &callable_custom_call;
info.is_valid_func = &callable_custom_is_valid;
info.free_func = &callable_custom_free;
info.hash_func = &callable_custom_hash;
info.equal_func = &callable_custom_equal_func;
info.less_than_func = &callable_custom_less_than_func;
info.hash_func = p_callable_custom->hash() != 0 ? &callable_custom_hash : nullptr;
info.equal_func = p_callable_custom->get_compare_equal_func() ? &callable_custom_equal_func : nullptr;
info.less_than_func = p_callable_custom->get_compare_less_func() ? &callable_custom_less_than_func : nullptr;
info.to_string_func = &callable_custom_to_string;
info.get_argument_count_func = &custom_callable_get_argument_count_func;

Expand Down

0 comments on commit 4d6f40a

Please sign in to comment.