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

Game hangs when calling load from a thread #55566

Open
jbpuryear opened this issue Dec 2, 2021 · 0 comments
Open

Game hangs when calling load from a thread #55566

jbpuryear opened this issue Dec 2, 2021 · 0 comments

Comments

@jbpuryear
Copy link

Godot version

3.4-1

System information

Arch Linux 5.15.5.arch1-1

Issue description

Game sometimes hangs when calling load from a thread, then calling wait_to_finish. I'm not sure, but I think it specifically happens when loading a resource that's not already in the cache. Adding a pause in the thread before the call to load with something like yield(get_tree().create_timer(0.001), "timeout") keeps the game from hanging, so I'm guessing it's some sort of mutex, race condition problem?

Possibly the same issue as #51225

Steps to reproduce

Add the following script to a node and set the file_path property to a resource not in the cache.

extends Node2D

export (String, FILE) var file_path

func _ready():
  var thread = Thread.new()
  thread.start(self, "hang_on_load", file_path)
  thread.wait_to_finish()

func hang_on_load(path):
#  Loading will work if you uncomment this line
#  yield(get_tree().create_timer(0.0001), "timeout")
  return load(path)

Minimal reproduction project

thread_loading_bug.zip

@YeldhamDev YeldhamDev added this to the 4.x milestone Sep 12, 2022
drwhut added a commit to drwhut/tabletop-club that referenced this issue Mar 9, 2023
One type of error that was occuring was the scene tree calling
`can_process()` on pieces that had just left the scene tree, but they
were still in the "idle_physics_process" group as the _physics_process
notification was being fired. This was solved by not removing the piece
from the scene tree early, and letting the queue_free() operation
remove it from the scene tree instead.

The game would also sometimes freeze at random intervals, with no errors
being thrown. After some debugging, I found that this freezing was
originating from the `load` call in `ResourceManager`, which was being
run inside a thread - thus I think the issue is the same as
godotengine/godot#55566. I implemented the same workaround mentioned
in that issue, and the game no longer freezes.

This commit closes #216.
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