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

Can't bind methods with the native pointer argument. #630

Closed
bruvzg opened this issue Sep 28, 2021 · 3 comments
Closed

Can't bind methods with the native pointer argument. #630

bruvzg opened this issue Sep 28, 2021 · 3 comments
Labels
bug This has been identified as a bug topic:gdextension This relates to the new Godot 4 extension implementation
Milestone

Comments

@bruvzg
Copy link
Member

bruvzg commented Sep 28, 2021

godot-cpp: 5826fd52592c5ed9051c7ef5dbfbd9295fb23607
godot: godotengine/godot#52192

Binding native pointer argument (both simple types and custom structure types register in the engine):

virtual void _font_set_data_ptr(const RID &font_rid, const uint8_t *p_data_ptr, uint64_t data_size);
...
virtual void _shaped_text_get_glyphs(const RID &shaped, const Glyph **r_glyphs) const;

Which was defined in the engine as:

virtual void font_set_data_ptr(RID p_font_rid, const uint8_t *p_data_ptr, size_t p_data_size) override;
GDVIRTUAL3(_font_set_data_ptr, RID, GDNativeConstPtr<const uint8_t>, uint64_t);
...
virtual const Glyph *shaped_text_get_glyphs(RID p_shaped) const override;
GDVIRTUAL2C(_shaped_text_get_glyphs, RID, GDNativePtr<const Glyph *>);

Fails with the following errors:

Simple type:

In file included from src/register_types.cpp:1:
In file included from ./godot-cpp/include/godot_cpp/core/class_db.hpp:38:
In file included from ./godot-cpp/include/godot_cpp/core/method_bind.hpp:34:
In file included from ./godot-cpp/include/godot_cpp/core/binder_common.hpp:36:
./godot-cpp/include/godot_cpp/core/method_ptrcall.hpp:179:134: error: type 'unsigned char' cannot be used prior to '::' because it has no members
                return reinterpret_cast<const T *>(godot::internal::interface->object_get_instance_binding((void *)p_ptr, godot::internal::token, &T::___binding_callbacks));
                                                                                                                                                   ^
./godot-cpp/include/godot_cpp/core/binder_common.hpp:152:39: note: in instantiation of member function 'godot::PtrToArg<const unsigned char *>::convert' requested here
        (p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...);
                                             ^
./godot-cpp/include/godot_cpp/core/binder_common.hpp:172:2: note: in instantiation of function template specialization 'godot::call_with_ptr_args_helper<godot::TextServerTest, const godot::RID &, const unsigned char *, unsigned long long, 0, 1, 2>' requested here
        call_with_ptr_args_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
        ^
./godot-cpp/gen/include/godot_cpp/classes/text_server_extension.hpp:266:4: note: in instantiation of function template specialization 'godot::call_with_ptr_args<godot::TextServerTest, const godot::RID &, const unsigned char *, unsigned long long>' requested here
                        BIND_VIRTUAL_METHOD(T, _font_set_data_ptr);
                        ^
./godot-cpp/include/godot_cpp/core/class_db.hpp:132:4: note: expanded from macro 'BIND_VIRTUAL_METHOD'
                        call_with_ptr_args(reinterpret_cast<m_class *>(p_instance), &m_class::m_method, p_args, p_ret);                       \
                        ^
src/ts_test.h:20:2: note: in instantiation of function template specialization 'godot::TextServerExtension::register_virtuals<godot::TextServerTest>' requested here
        GDCLASS(TextServerTest, TextServerExtension);
        ^
./godot-cpp/include/godot_cpp/classes/wrapped.hpp:122:16: note: expanded from macro 'GDCLASS'
                        m_inherits::register_virtuals<m_class>();                                                                                                             \
                                    ^
1 error generated.
scons: *** [src/register_types.os] Error 1

Pointer to the custom structure type:

In file included from src/register_types.cpp:1:
In file included from ./godot-cpp/include/godot_cpp/core/class_db.hpp:38:
In file included from ./godot-cpp/include/godot_cpp/core/method_bind.hpp:34:
In file included from ./godot-cpp/include/godot_cpp/core/binder_common.hpp:36:
./godot-cpp/include/godot_cpp/core/method_ptrcall.hpp:168:128: error: type 'const godot::Glyph *' cannot be used prior to '::' because it has no members
                return reinterpret_cast<T *>(godot::internal::interface->object_get_instance_binding((void *)p_ptr, godot::internal::token, &T::___binding_callbacks));
                                                                                                                                             ^
./godot-cpp/include/godot_cpp/core/binder_common.hpp:157:39: note: in instantiation of member function 'godot::PtrToArg<const godot::Glyph **>::convert' requested here
        (p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...);
                                             ^
./godot-cpp/include/godot_cpp/core/binder_common.hpp:177:2: note: in instantiation of function template specialization 'godot::call_with_ptr_argsc_helper<godot::TextServerTest, const godot::RID &, const godot::Glyph **, 0, 1>' requested here
        call_with_ptr_argsc_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
        ^
./godot-cpp/gen/include/godot_cpp/classes/text_server_extension.hpp:581:4: note: in instantiation of function template specialization 'godot::call_with_ptr_args<godot::TextServerTest, const godot::RID &, const godot::Glyph **>' requested here
                        BIND_VIRTUAL_METHOD(T, _shaped_text_get_glyphs);
                        ^
./godot-cpp/include/godot_cpp/core/class_db.hpp:132:4: note: expanded from macro 'BIND_VIRTUAL_METHOD'
                        call_with_ptr_args(reinterpret_cast<m_class *>(p_instance), &m_class::m_method, p_args, p_ret);                       \
                        ^
src/ts_test.h:20:2: note: in instantiation of function template specialization 'godot::TextServerExtension::register_virtuals<godot::TextServerTest>' requested here
        GDCLASS(TextServerTest, TextServerExtension);
        ^
./godot-cpp/include/godot_cpp/classes/wrapped.hpp:122:16: note: expanded from macro 'GDCLASS'
                        m_inherits::register_virtuals<m_class>();                                                                                                             \
                                    ^
1 error generated.
scons: *** [src/register_types.os] Error 1

Similar errors happen if methods are defined with void * pointers (as they are defined in the base TextServerExtension generated header).

@bruvzg bruvzg added bug This has been identified as a bug topic:gdextension This relates to the new Godot 4 extension implementation labels Sep 28, 2021
@bruvzg bruvzg added this to the 4.0 milestone Sep 28, 2021
@Faless
Copy link
Contributor

Faless commented Sep 28, 2021

Base types pointers are now supported after #625

@bruvzg
Copy link
Member Author

bruvzg commented Sep 28, 2021

Base types pointers are now supported after #625

Custom pointers also work, if I add the following code to the module header, but probably it should be auto generated (or added to godot-cpp).

GDVIRTUAL_NATIVE_PTR(Glyph *);
GDVIRTUAL_NATIVE_PTR(CaretInfo);

@bruvzg
Copy link
Member Author

bruvzg commented Feb 21, 2022

This is fixed by godotengine/godot#57587, #704 and #699

@bruvzg bruvzg closed this as completed Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This has been identified as a bug topic:gdextension This relates to the new Godot 4 extension implementation
Projects
None yet
Development

No branches or pull requests

2 participants