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

Fix thread start with no user data when target has no default argument #51093

Merged
merged 1 commit into from
Aug 3, 2021

Conversation

RandomShaper
Copy link
Member

This fixes the case where no user data is specified to start a thread with a target method taking one parameter with no default value.

This script has been used the test the outcomes before and after this PR:

var thread: Thread

func _ready():
	thread = Thread.new()
	for i in range(1, 5):
		print("Case %d" % i)
		thread.start(self, "do_stuff_%d" % i)
		prints("Passing nothing", "WORKED" if thread.wait_to_finish() else "FAILED")
		thread.start(self, "do_stuff_%d" % i, "User data")
		prints("Passing string", "WORKED" if thread.wait_to_finish() else "FAILED")
		thread.start(self, "do_stuff_%d" % i, 666)
		prints("Passing integer", "WORKED" if thread.wait_to_finish() else "FAILED")

func do_stuff_1(optional_var: int):
	return true

func do_stuff_2(optional_var: int = 0):
	return true

func do_stuff_3(optional_var):
	return true

func do_stuff_4(optional_var = null):
	return true

These are the results:

  • Case 1 (optional_var: int)

    • Before & after
      • Passing nothing FAILED (Too Few Arguments)
      • Passing string FAILED (Invalid Argument #0)
      • Passing integer WORKED
  • Case 2 (optional_var: int = 0)

    • Before & after
      • Passing nothing WORKED
      • Passing string FAILED (Invalid Argument #0)
      • Passing integer WORKED
  • Case 3 (optional_var)

    • Before
      • Passing nothing FAILED (Too Few Arguments)
      • Passing string WORKED
      • Passing integer WORKED
    • After
      • Passing nothing WORKED
      • Passing string WORKED
      • Passing integer WORKED
  • Case 4 (optional_var = null)

    • Before & after
      • Passing nothing WORKED
      • Passing string WORKED
      • Passing integer WORKED

Fixes #50692.

@RandomShaper RandomShaper added bug topic:core cherrypick:3.x Considered for cherry-picking into a future 3.x release labels Jul 31, 2021
@RandomShaper RandomShaper added this to the 4.0 milestone Jul 31, 2021
@RandomShaper RandomShaper requested a review from a team as a code owner July 31, 2021 08:09
@akien-mga akien-mga merged commit 8e4848a into godotengine:master Aug 3, 2021
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 3.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Starting a thread from GDScript always require non-null data to be passed
2 participants