Fixed pointer indirection in the PtrToArg template for Object arguments.#677
Conversation
Contributor
|
This patch fixes the similar case #655 for --- a/include/godot_cpp/classes/ref.hpp
+++ b/include/godot_cpp/classes/ref.hpp
@@ -240,7 +240,7 @@ public:
template <class T>
struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
- return Ref<T>(godot::internal::gdn_interface->object_get_instance_binding((void *)p_ptr, godot::internal::token, &T::___binding_callbacks));
+ return Ref<T>(reinterpret_cast<T*>(godot::internal::gdn_interface->object_get_instance_binding(*(const GDNativeObjectPtr *)p_ptr, godot::internal::token, &T::___binding_callbacks)));
}
typedef Ref<T> EncodeT;
@@ -255,7 +255,7 @@ struct PtrToArg<const Ref<T> &> {
typedef Ref<T> EncodeT;
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
- return Ref<T>(godot::internal::gdn_interface->object_get_instance_binding((void *)p_ptr, godot::internal::token, &T::___binding_callbacks));
+ return Ref<T>(reinterpret_cast<T*>(godot::internal::gdn_interface->object_get_instance_binding(*(const GDNativeObjectPtr *)p_ptr, godot::internal::token, &T::___binding_callbacks)));
}
};@lukas-toenne Could you include this in your PR? |
Patch by Nana Sakisaka (saki7).
Contributor
|
Thanks! |
|
I can also confirm that these two commits fix #655 |
Faless
approved these changes
Jul 28, 2022
Contributor
Faless
left a comment
There was a problem hiding this comment.
It took me a bit to fully understand what was going on, but this is correct.
Really excellent work both 🏅 🎆 !
And sorry for the very late review :/ it's been some crazy times, but we are finally moving into stabilization :).
Contributor
|
Note to self, we should probably add a test for this, I had one, but it's not great for CI, maybe an |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Object pointer arguments for virtual function callbacks are not correctly converted by the
PtrToArgtemplate in godot-cpp. It is missing one level of pointer indirection, passing the void* wrapper directly to thegdnative_object_get_instance_bindingimplementation, which expects aObject*.This patch adds the additional pointer dereference, which brings it in line with the core Godot
PtrToArgtemplate.This fixes #651