-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Nested coroutines crash the engine after freeing the executing node #47703
Comments
This makes sure all coroutines ended before calling queue_free() which currently causes memory problems. See godotengine/godot#47703
This makes sure all coroutines ended before calling queue_free() which currently causes memory problems. See godotengine/godot#47703
I ported the given script to GDScript 2.0 and ran it in v4.0.dev.20211015.official [f113dc9] extends Node
var timer: Timer
func _ready():
timer = Timer.new()
add_child(timer)
timer.start()
coro() # switching this to coro_ok() fixes the crash
queue_free()
print("Incoming Crash/Memory corruption")
func wait(time: float):
timer.wait_time = time
timer.start()
await timer.timeout
func coro():
while true:
await wait(1.0)
print("Please don't free me")
func coro_ok():
while true:
timer.wait_time = 1.0
timer.start()
await timer.timeout
print("You can free me!")
Neither coro() nor coro_ok() will crash the engine when used. On v3.4.rc2.official.23955fc28, it is also fixed, somehow. Edit: oh, I should mention I ran them presumably without asan. So they may still be present, but it doesn't appear to affect the official builds here. |
I was talking about concurrency in Godot with a small discord group. And, the issue around freeing an objects which have pending coroutines came up. I can confirm this issue forced me to upgrade a project from Godot 3.0 to Godot 4.0 (where the issue has been fixed for This bug is highly non-deterministic, but will always fail when ran with an address sanitizer (see #74695). |
Closed by #97464. |
Godot version: 3.2.3(tag) and 3.3rc7(hash mentioned in news post), both built using asan=True
OS/device including version:
Linux x64 for reproduction, but issue happened on Windows and WASM/Web build too
Issue description:
When running the minimal example project without the address sanitizer everything seems fine at first at first, but eventually the engine would crash. That's what happened in a bigger project of mine. After investigation I found out that it is caused by waiting on a coroutine to complete while also trying to free the corresponding node(see example below).
Steps to reproduce:
Minimal reproduction project:
The following script attached to any node will trigger the crash/memory corruption:
coro_crash.zip
The text was updated successfully, but these errors were encountered: