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

Thread requires argument even when not providing 'userdata' #36032

Closed
EduardoLemos567 opened this issue Feb 8, 2020 · 2 comments · Fixed by #37452
Closed

Thread requires argument even when not providing 'userdata' #36032

EduardoLemos567 opened this issue Feb 8, 2020 · 2 comments · Fixed by #37452

Comments

@EduardoLemos567
Copy link

OS: Windows 7 SP1
Godot version: 3.2

Bug:
When you call Thread.start using a method which doesnt accept arguments, the following error occurs:

E 0:00:00.431 _start_func: Could not call function 'work' to start thread 4788: Too Many Arguments.
<C++ Error> Method failed.
<C++ Source> core/bind/core_bind.cpp:2694 @ _start_func()

Example code:

extends Spatial

var _thread = Thread.new()

func work(): 
	print('done')

func _ready():
	_thread.start(self, "work")

Probably the internal call try to pass some argument and since work() doenst accept, it throws that error.
The code bellow runs fine:

extends Spatial

var _thread = Thread.new()

func work(abc): # <---
	print('done')

func _ready():
	_thread.start(self, "work")
@Calinou
Copy link
Member

Calinou commented Feb 8, 2020

This is documented on Using multiple threads, but it doesn't explain why the userdata parameter must always be specified.

@EduardoLemos567
Copy link
Author

I overlooked the doc (my mistake) about the Thread.start(), it was there:

Starts a new Thread that runs method on object instance with userdata passed as an argument. 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.

Maybe making it more clearer (like the tutorial you linked):

Starts a new Thread that runs method on object instance with userdata passed as an argument (even if no userdata argument is passed, the 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.

zak-grumbles added a commit to zak-grumbles/godot that referenced this issue Mar 31, 2020
* Updated docs for Thread.start() to specify that the method argument
must accept one parameter.
akien-mga added a commit that referenced this issue Mar 31, 2020
@akien-mga akien-mga added this to the 4.0 milestone Mar 31, 2020
akien-mga pushed a commit that referenced this issue Apr 6, 2020
* Updated docs for Thread.start() to specify that the method argument
must accept one parameter.

(cherry picked from commit d09644d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants