godotengine / godotengine/godot-cpp
Can't compile if has a custom class which inherit from `EditorInspectorPlugin`.
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
After [#897](https://github.com/godotengine/godot-cpp/pull/897).
This method:
`virtual bool EditorInspectorPlugin::_parse_property(Object *object, int64_t type, const String &name, int64_t hint_type, const String &hint_string, int64_t usage_flags, bool wide);`

Can't convert `GDNativeConstObjectPtr` to `GDNativeObjectPtr`.
I try to use `GDNativeObjectPtr` instead of `GDNativeConstObjectPtr` in this template and compiled successfully.
However, It dosen't work and will crash when Godot side try to call my custom `EditorInspectorPlugin::_parse_property()`( follow content are happen before [#897](https://github.com/godotengine/godot-cpp/pull/897), too).
The stack as follow:

I don't know why it will crash with mutex, it is quite weird.
I'm sure this problem is relate on `PtrToArg::convert(const void *p_ptr)`
I implement a template specialization for `Object *` as follow:
```
template <>
struct PtrToArg {
_FORCE_INLINE_ static Object *convert(const void *p_ptr) {
return *(Object **)(p_ptr);
}
typedef Object *EncodeT;
_FORCE_INLINE_ static void encode(Object *p_var, void *p_ptr) {
*reinterpret_cast(p_ptr) = p_var;
}
};
```
It will successfully work with my custom `EditorInspectorPlugin::_parse_property()`, but other functions will become weird.
At last, I try to combine my implement and the template for `Object`, like this:
```
template
struct PtrToArg {
_FORCE_INLINE_ static T *convert(const void *p_ptr) {
auto ptr = (Object **)(p_ptr);
if(auto obj = Object::cast_to(*ptr)){
return obj;
}
return reinterpret_cast(godot::internal::gdn_interface->object_get_instance_binding(*reinterpret_cast(const_cast(p_ptr)), godot::internal::token, &T::___binding_callbacks));
}
typedef Object *EncodeT;
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
*reinterpret_cast(p_ptr) = p_var ? p_var->_owner : nullptr;
}
};
```
However, the variable `ptr` alway be a `nullptr` and execute old behavior( crash with mutex lock).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.