VisualServer instance_create() returns invalid RID
The instance_create() method of the VisualServer singleton returns invalid RID
example:
// Somewhere in _ready() or _process()
let mut vs = VisualServer::godot_singleton();
let rid = vs.instance_create();
println!("id of Rid is {}", rid.get_id());
// id of Rid is 0
Looking at the function in the bindings:
pub unsafe fn VisualServer_instance_create(obj_ptr: *mut sys::godot_object) -> Rid {
let gd_api = get_api();
let method_bind: *mut sys::godot_method_bind = VisualServerMethodTable::get(gd_api).instance_create;
let mut argument_buffer : [*const libc::c_void; 0] = [
];
let mut ret: *mut sys::godot_object = ptr::null_mut();
let ret_ptr = (&mut ret) as *mut _;
(gd_api.godot_method_bind_ptrcall)(method_bind, obj_ptr, argument_buffer.as_mut_ptr() as *mut _, ret_ptr as *mut _);
let mut rid = Rid::default();
(gd_api.godot_rid_new_with_resource)(rid.mut_sys(), ret);
rid
}
Does ret not contain a RID already?
So instead of
let mut ret: *mut sys::godot_object = ptr::null_mut();
let ret_ptr = (&mut ret) as *mut _;
(gd_api.godot_method_bind_ptrcall)(method_bind, obj_ptr, argument_buffer.as_mut_ptr() as *mut _, ret_ptr as *mut _);
let mut rid = Rid::default();
(gd_api.godot_rid_new_with_resource)(rid.mut_sys(), ret);
rid
would something like this work?
let mut ret: sys::godot_rid = sys::godot_rod::default();
let ret_ptr = (&mut ret) as *mut _;
(gd_api.godot_method_bind_ptrcall)(method_bind, obj_ptr, argument_buffer.as_mut_ptr() as *mut _, ret_ptr as *mut _);
Rid::from_sys(ret)
I'm just speculating as there is not much documentation on GDNative and Nativescript
Interesting. It seems like the code that's generated when a RID is returned is wrong.
Your corrected code looks a lot more like what I would expect.
Seems like this is what causes this:
The generation of the ret variable binding is wrong
https://github.com/GodotNativeTools/godot-rust/blob/257552be9a2f53c051183b5600fad96b126c31f0/bindings_generator/src/methods.rs#L466
The conversion to the actual return value is also wrong https://github.com/GodotNativeTools/godot-rust/blob/257552be9a2f53c051183b5600fad96b126c31f0/bindings_generator/src/methods.rs#L518