godot: Thread does not start with a method with no arguments
ElementaryOS 0.4.1 (Ubuntu 17) - Godot version: 2.1.3
Thread does not start with a method with no arguments This node works:
extends Node
var thread = null
func _ready():
thread = Thread.new()
var err = thread.start(self, "work")
func work(userdata):
print("oi")
while(true):
print("oi")
But this does not:
extends Node
var thread = null
func _ready():
thread = Thread.new()
var err = thread.start(self, "work")
func work():
print("oi")
while(true):
print("oi")
I found this error during my question (https://godotengine.org/qa/16730/thread-not-running), but only by adding the argument did the method start to run.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 36 (35 by maintainers)
@schweigert it’s better if you open a new issue with your suggestion.
@schweigert I think, if we introduce a new keyword for threads, it should be located at the function invocation rather than at the function itself.
This would still allow us to call the method synchronously. I don’t know if it’s worth a new syntax sugar keyword though.
An option would be to make
Thread.start
a vararg method.Ok, then that’s a bug IMO. It should be:
prints:
i.e. just like
connect()
orcall_deferred()
work.I can confirm that it’s fixed in 3.4 beta 2 (so it was fixed by #38078).
Did someone fix this bug? It seems the workaround in the Voxel demo isn’t necessary in 3.4. https://github.com/godotengine/godot-demo-projects/pull/639
Was making a thread in my demo project today and i made a thread with no argument and ofc it did not work, and then after awhile i remembered this error 😃
Its extremely confusing to have the Thread.start() fail if the method called in the thread has no arguments. If I don’t pass any userdata to the Thread.start() method then it should not try passing an empty array to the method I’m calling in the thread.
If we keep it like that we should consider allowing 0 parameters for convenience reasons and to prevent confusion.
No, if you pass no arguments the parameter in the start method defaults to an empty array.
The OP’s problem is, that the thread doesn’t start even if there are no arguments given. This is intended.
Now we can discuss if the thread should start if the thread method has no parameters defined (
func work():
) and no arguments are given (thread.start(self, "work")
) for convenience reasons and to prevent confusion for beginners.I think Threads should still start even if there are no parameters defined in the Thread method signature.
My proposal:
.start
method but no parameters are defined → Show an error, or even better crash the game with an errornull
or[]