I am trying to start a thread but nothing is happening (no error message, no panic). This is in Rust using the gdnative
crate. I assume that I have done something wrong with the parameters, but I am having problems understanding the documentation; I have tried a few alternatives, but nothing seems to work. The rest of my code seems to work.
My call is:
self.generator_thread
.start(
Some(unsafe { _owner.to_object() }),
GodotString::from_str("thread_function"),
Variant::from_array(&VariantArray::new()),
Thread::PRIORITY_NORMAL,
)
.unwrap();
The declaration of the method is:
#[export]
fn thread_function(&mut self, mut _owner: Node2D, _userdata: Variant)
The rust call (from the API doco) is:
pub fn start(
&mut self,
instance: Option<Object>,
method: GodotString,
userdata: Variant,
priority: i64
) -> Result<(), GodotError>
The Godot API doco has
Error start ( Object instance, String method, Variant userdata=null, Priority priority=1 )
Starts a new Thread that runs method on object instance with userdata passed as an argument. Even if no userdata is passed, method must accept one argument and it will be null. The priority of the Thread can be changed by passing a value from the Priority enum.
Returns @GlobalScope.OK on success, or @GlobalScope.ERR_CANT_CREATE on failure.
I previously wrote the code in GDScript:
generator_thread.start(self, "_thread_function", "")
and
func _thread_function(userdata):
and that worked without any problems.