Skip to content

Can't bind methods using Ref<T> as return type or argument #628

Closed

Description

@akien-mga

godot-cpp version: a44e9aa

I played a bit trying to port a Godot module (opensimplex) to GDExtension, and I ran into an issue binding methods which are using Ref<T> either as return or as argument type.

Here's a simpler reproduction in the example test:

diff --git a/godot-headers b/godot-headers
index ea1808a..f879e52 160000
--- a/godot-headers
+++ b/godot-headers
@@ -1 +1 @@
-Subproject commit ea1808a146ba8f30c4d16e057b90d45e8732cbba
+Subproject commit f879e52dedc74b42197d05cf3f606eb0a7d2654a
diff --git a/test/src/example.cpp b/test/src/example.cpp
index e3ed316..3c6f5be 100644
--- a/test/src/example.cpp
+++ b/test/src/example.cpp
@@ -53,6 +53,8 @@ void Example::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("return_something"), &Example::return_something);
 	ClassDB::bind_method(D_METHOD("return_something_const"), &Example::return_something_const);
 	ClassDB::bind_method(D_METHOD("return_extended_ref"), &Example::return_extended_ref);
+	ClassDB::bind_method(D_METHOD("get_empty_image"), &Example::get_empty_image);
+	ClassDB::bind_method(D_METHOD("is_image_valid", "img"), &Example::is_image_valid);
 
 	{
 		MethodInfo mi;
@@ -116,6 +118,14 @@ void Example::emit_custom_signal(const String &name, int value) {
 	emit_signal("custom_signal", name, value);
 }
 
+Ref<Image> Example::get_empty_image() const {
+	return Ref<Image>();
+}
+
+bool Example::is_image_valid(const Ref<Image> &img) const {
+	return img.is_valid();
+}
+
 // Properties.
 void Example::set_custom_position(const Vector2 &pos) {
 	custom_position = pos;
diff --git a/test/src/example.h b/test/src/example.h
index e72051b..a0cabf7 100644
--- a/test/src/example.h
+++ b/test/src/example.h
@@ -32,7 +32,9 @@
 #define EXAMPLE_CLASS_H
 
 #include <godot_cpp/classes/control.hpp>
+#include <godot_cpp/classes/image.hpp>
 #include <godot_cpp/classes/global_constants.hpp>
+#include <godot_cpp/classes/ref_counted.hpp>
 #include <godot_cpp/classes/viewport.hpp>
 
 #include <godot_cpp/core/binder_common.hpp>
@@ -78,6 +80,9 @@ public:
 	ExampleRef *return_extended_ref() const;
 	Variant varargs_func(const Variant **args, GDNativeInt arg_count, GDNativeCallError &error);
 	void emit_custom_signal(const String &name, int value);
+	// Test Ref<T> as return type or argument.
+	Ref<Image> get_empty_image() const;
+	bool is_image_valid(const Ref<Image> &img) const;
 
 	// Property.
 	void set_custom_position(const Vector2 &pos);

If the bind_method calls are commented out, it builds fine, but if either or both are compiled, then it throws a ton of errors:

$ scons target=debug
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o src/example.os -c -std=c++17 -fPIC -g3 -Og -fPIC -DDEBUG_ENABLED -DDEBUG_METHODS_ENABLED -I. -I/home/akien/Projects/godot/gdnative/godot-cpp/godot-headers -I/home/akien/Projects/godot/gdnative/godot-cpp/include -I/home/akien/Projects/godot/gdnative/godot-cpp/gen/include -Isrc src/example.cpp
In file included from /home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/class_db.hpp:38,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/gen/include/godot_cpp/classes/ref_counted.hpp:39,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/classes/ref.hpp:37,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/gen/include/godot_cpp/classes/texture2d.hpp:38,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/gen/include/godot_cpp/classes/canvas_item.hpp:37,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/gen/include/godot_cpp/classes/control.hpp:38,
                 from src/example.h:34,
                 from src/example.cpp:31:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp: In instantiation of ‘GDNativeVariantType godot::MethodBindTRC<R, P>::gen_argument_type(int) const [with R = godot::Ref<godot::Image>; P = {}]’:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:469:30:   required from here
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:473:48: error: incomplete type ‘godot::GetTypeInfo<godot::Ref<godot::Image>, void>’ used in nested name specifier
  473 |                         return GetTypeInfo<R>::VARIANT_TYPE;
      |                                                ^~~~~~~~~~~~
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp: In instantiation of ‘GDNativePropertyInfo godot::MethodBindTRC<R, P>::gen_argument_type_info(int) const [with R = godot::Ref<godot::Image>; P = {}]’:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:477:31:   required from here
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:483:62: error: incomplete type ‘godot::GetTypeInfo<godot::Ref<godot::Image>, void>’ used in nested name specifier
  483 |                         return GetTypeInfo<R>::get_class_info();
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp: In instantiation of ‘GDNativeExtensionClassMethodArgumentMetadata godot::MethodBindTRC<R, P>::get_argument_metadata(int) const [with R = godot::Ref<godot::Image>; P = {}]’:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:491:55:   required from here
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:495:48: error: incomplete type ‘godot::GetTypeInfo<godot::Ref<godot::Image>, void>’ used in nested name specifier
  495 |                         return GetTypeInfo<R>::METADATA;
      |                                                ^~~~~~~~
In file included from /home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:34,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/class_db.hpp:38,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/gen/include/godot_cpp/classes/ref_counted.hpp:39,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/classes/ref.hpp:37,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/gen/include/godot_cpp/classes/texture2d.hpp:38,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/gen/include/godot_cpp/classes/canvas_item.hpp:37,
                 from /home/akien/Projects/godot/gdnative/godot-cpp/gen/include/godot_cpp/classes/control.hpp:38,
                 from src/example.h:34,
                 from src/example.cpp:31:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of ‘void godot::call_get_argument_type_helper(int, int&, GDNativeVariantType&) [with Q = const godot::Ref<godot::Image>&]’:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:398:53:   required from ‘GDNativeVariantType godot::call_get_argument_type(int) [with P = {const godot::Ref<godot::Image>&}]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:471:39:   required from ‘GDNativeVariantType godot::MethodBindTRC<R, P>::gen_argument_type(int) const [with R = bool; P = {const godot::Ref<godot::Image>&}]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:469:30:   required from here
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:387:40: error: incomplete type ‘godot::GetTypeInfo<const godot::Ref<godot::Image>&, void>’ used in nested name specifier
  387 |                 type = GetTypeInfo<Q>::VARIANT_TYPE;
      |                                        ^~~~~~~~~~~~
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of ‘void godot::call_get_argument_type_info_helper(int, int&, GDNativePropertyInfo&) [with Q = const godot::Ref<godot::Image>&]’:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:417:58:   required from ‘void godot::call_get_argument_type_info(int, GDNativePropertyInfo&) [with P = {const godot::Ref<godot::Image>&}]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:480:37:   required from ‘GDNativePropertyInfo godot::MethodBindTRC<R, P>::gen_argument_type_info(int) const [with R = bool; P = {const godot::Ref<godot::Image>&}]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:477:31:   required from here
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:407:54: error: incomplete type ‘godot::GetTypeInfo<const godot::Ref<godot::Image>&, void>’ used in nested name specifier
  407 |                 info = GetTypeInfo<Q>::get_class_info();
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of ‘void godot::call_get_argument_metadata_helper(int, int&, GDNativeExtensionClassMethodArgumentMetadata&) [with Q = const godot::Ref<godot::Image>&]’:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:437:57:   required from ‘GDNativeExtensionClassMethodArgumentMetadata godot::call_get_argument_metadata(int) [with P = {const godot::Ref<godot::Image>&}]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:493:43:   required from ‘GDNativeExtensionClassMethodArgumentMetadata godot::MethodBindTRC<R, P>::get_argument_metadata(int) const [with R = bool; P = {const godot::Ref<godot::Image>&}]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:491:55:   required from here
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:425:38: error: incomplete type ‘godot::GetTypeInfo<const godot::Ref<godot::Image>&, void>’ used in nested name specifier
  425 |                 md = GetTypeInfo<Q>::METADATA;
      |                                      ^~~~~~~~
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of ‘void godot::call_with_ptr_args_retc_helper(T*, R (T::*)(P ...) const, void* const*, void*, IndexSequence<Is ...>) [with T = godot::___UnexistingClass; R = bool; P = {const godot::Ref<godot::Image>&}; long unsigned int ...Is = {0}; GDNativeTypePtr = void*]’:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:187:44:   required from ‘void godot::call_with_ptr_args(T*, R (T::*)(P ...) const, void* const*, void*) [with T = godot::___UnexistingClass; R = bool; P = {const godot::Ref<godot::Image>&}; GDNativeTypePtr = void*]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:512:36:   required from ‘void godot::MethodBindTRC<R, P>::ptrcall(GDExtensionClassInstancePtr, void* const*, GDNativeTypePtr) const [with R = bool; P = {const godot::Ref<godot::Image>&}; GDExtensionClassInstancePtr = void*; GDNativeTypePtr = void*]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:508:15:   required from here
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:167:73: error: ‘convert’ is not a member of ‘godot::PtrToArg<const godot::Ref<godot::Image>&>’
  167 |         PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret);
      |                                                     ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of ‘void godot::call_with_ptr_args_retc_helper(T*, R (T::*)(P ...) const, void* const*, void*, IndexSequence<Is ...>) [with T = godot::___UnexistingClass; R = godot::Ref<godot::Image>; P = {}; long unsigned int ...Is = {}; GDNativeTypePtr = void*]’:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:187:44:   required from ‘void godot::call_with_ptr_args(T*, R (T::*)(P ...) const, void* const*, void*) [with T = godot::___UnexistingClass; R = godot::Ref<godot::Image>; P = {}; GDNativeTypePtr = void*]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:512:36:   required from ‘void godot::MethodBindTRC<R, P>::ptrcall(GDExtensionClassInstancePtr, void* const*, GDNativeTypePtr) const [with R = godot::Ref<godot::Image>; P = {}; GDExtensionClassInstancePtr = void*; GDNativeTypePtr = void*]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:508:15:   required from here
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:167:28: error: ‘encode’ is not a member of ‘godot::PtrToArg<godot::Ref<godot::Image> >’
  167 |         PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret);
      |         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp: In instantiation of ‘static T godot::VariantCasterAndValidate<const T&>::cast(const godot::Variant**, uint32_t, GDNativeCallError&) [with T = godot::Ref<godot::Image>; uint32_t = unsigned int]’:
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:230:67:   required from ‘void godot::call_with_variant_args_retc_helper(T*, R (T::*)(P ...) const, const godot::Variant**, godot::Variant&, GDNativeCallError&, IndexSequence<Is ...>) [with T = godot::___UnexistingClass; R = bool; P = {const godot::Ref<godot::Image>&}; long unsigned int ...Is = {0}]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:374:36:   required from ‘void godot::call_with_variant_args_retc_dv(T*, R (T::*)(P ...) const, void* const*, int, godot::Variant&, GDNativeCallError&, const std::vector<godot::Variant>&) [with T = godot::___UnexistingClass; R = bool; P = {const godot::Ref<godot::Image>&}; GDNativeVariantPtr = void*]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:504:33:   required from ‘godot::Variant godot::MethodBindTRC<R, P>::call(GDExtensionClassInstancePtr, void* const*, GDNativeInt, GDNativeCallError&) const [with R = bool; P = {const godot::Ref<godot::Image>&}; GDExtensionClassInstancePtr = void*; GDNativeVariantPtr = void*; GDNativeInt = long int]’
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/method_bind.hpp:499:18:   required from here
/home/akien/Projects/godot/gdnative/godot-cpp/include/godot_cpp/core/binder_common.hpp:138:63: error: incomplete type ‘godot::GetTypeInfo<godot::Ref<godot::Image>, void>’ used in nested name specifier
  138 |                 GDNativeVariantType argtype = GetTypeInfo<T>::VARIANT_TYPE;
      |                                                               ^~~~~~~~~~~~
scons: *** [src/example.os] Error 1
scons: building terminated because of errors.

Activity

  1. added
    bug
    topic:gdextension
    on Sep 28, 2021
  2. added this to the 4.0 milestone on Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtopic:gdextension

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions