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

Misleading error when starting thread on Node member function with missing argument binding #78924

Open
briansemrau opened this issue Jul 2, 2023 · 3 comments

Comments

@briansemrau
Copy link
Contributor

Godot version

4.1.rc2

System information

Windows 10

Issue description

Prior to 4.1, I was able to start a thread from a Node that ran a member function:

extends Node

var _thread: Thread = Thread.new()

func _ready():
    _thread.start(_run_thread)

func _run_thread(_userdata) -> void:
    # do work
    return

error:

E 0:00:01:0862   Node::get_script: Caller thread can't call this function in this node (/root/Game/InfiniteCubeTerrain). Use call_deferred() or call_thread_group() instead.
  <C++ Error>    Condition "!is_accessible_from_caller_thread()" is true. Returning: (Variant())
  <C++ Source>   scene\main\node.cpp:3540 @ Node::get_script()

This functionality remains broken after the threading changes in 4.1, which was not restored for my use case by #78000.

I cannot call Thread.set_thread_safety_checks_enabled(false) because my run function is prevented from starting.

It looks like this would work if I was using a Reference type, not a Node type:

https://github.com/godotengine/godot/blob/46424488edc341b65467ee7fd3ac423e4d49ad34/scene/main/node.cpp#L3539-L3542C2

Steps to reproduce

See above

Minimal reproduction project

N/A

@heppocogne
Copy link
Contributor

heppocogne commented Jul 2, 2023

Passing an argument solves the issue in this case:

func _ready():
	_thread.start(_run_thread.bind("a"))

The error message is wrong.

@briansemrau
Copy link
Contributor Author

briansemrau commented Jul 2, 2023

Passing an argument solves the issue in this case

Have you tested it? This does not fix the issue in my project.

Looks like this works in a minimal example. Not sure what's different in my project that causes this to break.

@briansemrau
Copy link
Contributor Author

Looks like the errors were quite misleading. Thank you for the help.

@akien-mga akien-mga changed the title GDScript Can't start thread on Node member function Misleading error when starting thread on Node member function with missing argument binding Jul 2, 2023
@akien-mga akien-mga reopened this Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants