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

Starting a thread from GDScript always require non-null data to be passed #50692

Closed
m4nu3lf opened this issue Jul 21, 2021 · 3 comments · Fixed by #51093
Closed

Starting a thread from GDScript always require non-null data to be passed #50692

m4nu3lf opened this issue Jul 21, 2021 · 3 comments · Fixed by #51093

Comments

@m4nu3lf
Copy link
Contributor

m4nu3lf commented Jul 21, 2021

Godot version

3.x build 51f8247

System information

OS: Arch Linux, CPU: Ryzen 5, GUP: RX 480

Issue description

When calling Thread.start() with null data the thread doesn't start and this error is reported:

ERROR: Could not call function 'thread_run' to start thread 5559469359093562243: Too Few Arguments.
   at: _start_func (core/bind/core_bind.cpp:2604)

It used to be possible to not specify the user data parameter and have that default to null.
Forcing the user to pass in some non-null data seems unnecessary.

Steps to reproduce

  • Create a scene with a single node and a script for the node.
  • Create a thread in the "_ready" method and start it by calling a function on the same script and specifying no data:
var my_thread: Thread = Thread.new()

func thread_run(_data) -> void:
  pass
  
func _ready():
  my_thread.start(self, "thread_run")

Minimal reproduction project

No response

@akien-mga
Copy link
Member

Likely a regression from #38078, CC @Faymoon @RandomShaper.

@akien-mga
Copy link
Member

akien-mga commented Jul 21, 2021

I'm not sure that's a bug though, this might just be the consequence of the bugfix.

If there's a parameter without a default value, it must be passed.

Confirmed that it works fine when specifying a fallback value:

var my_thread: Thread = Thread.new()

func thread_run(_data = null) -> void:
  pass
  
func _ready():
  my_thread.start(self, "thread_run")

What would you expect _data to be initialized to if it's not assigned a default value and not passed in the start() call?

@akien-mga akien-mga changed the title Starting a thread form GDScript always require non-null data to be passed Starting a thread from GDScript always require non-null data to be passed Jul 21, 2021
@m4nu3lf
Copy link
Contributor Author

m4nu3lf commented Jul 21, 2021

There is null default value defined in the start method as userdata, I would expect that to be used if no data is specified.

start(instance: Object, method: String, userdata: Variant = null, priority: Priority = 1)

I understand it can work that way too, but it is a bit surprising to me.

Also no nulls are allowed unless the target function specifies a default null value too.

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.

2 participants