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

assert from a thread does not function as expected #85523

Closed
tjbrockmeyer opened this issue Nov 29, 2023 · 3 comments
Closed

assert from a thread does not function as expected #85523

tjbrockmeyer opened this issue Nov 29, 2023 · 3 comments

Comments

@tjbrockmeyer
Copy link

tjbrockmeyer commented Nov 29, 2023

Godot version

v4.1.3.stable.official [f06b6836a]

System information

Godot v4.1.3.stable - Linux Mint 21.1 (Vera) - X11 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 1070 (nvidia; 525.125.06) - AMD Ryzen 7 1700 Eight-Core Processor (16 Threads)

Issue description

When using assert from a thread, I expect that the execution would halt the same as when using assert on the main thread. Instead, it forces the caller of assert to return immediately with the "default" value (null for references, false for bool, 0 for int, etc). No error messages are created whatsoever, and execution is not halted. This can cause extremely hard-to-detect bugs that will disappear or transform in a release build. The documentation does not say anything about assert having different functionality on threads other than the main thread, only that you "must be running in the editor," which my assumption was that a new thread is, in fact, still running in the editor.

Steps to reproduce

Create a thread, call a function from inside that thread, call assert(false) from the called function. Then observe that there is no halt for the debugger, there are no error messages, the return value of the called function is the "default" value of the function's return type, and the thread ran to completion despite a failed assert call.

Minimal reproduction project

The following script is enough to reproduce this issue.

extends Node

func _ready() -> void:
	var thread = Thread.new()
	thread.start(_run_thread)
	thread.wait_to_finish()

func _run_thread():
	print('thread running...')
	var result = _fn()
	prints('result:', result)

func _fn() -> int:
	assert(false)
	return 200

Expected output:

thread running...
result: 200

Actual output:

thread running...
result: 0
@jsjtxietian
Copy link
Contributor

I got a debug break using your code in Godot v4.2.rc (830f29422) - Windows 10.0.22621 - GLES3 (Compatibility) - NVIDIA GeForce RTX 3060 Ti (NVIDIA; 31.0.15.4601) - 12th Gen Intel(R) Core(TM) i7-12700F (20 Threads):

image

@AThousandShips
Copy link
Member

Probably fixed by:

So a duplicate of:

@tjbrockmeyer
Copy link
Author

Good to know that it is fixed. I didn't find those other issues when searching for assert. Awaiting the fix in the stable release 😄

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

4 participants