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

call_group() fails silently #32186

Closed
ghost opened this issue Sep 18, 2019 · 5 comments · Fixed by #97240
Closed

call_group() fails silently #32186

ghost opened this issue Sep 18, 2019 · 5 comments · Fixed by #97240

Comments

@ghost
Copy link

ghost commented Sep 18, 2019

Godot version:
3.1
Issue description:
call_group() will silently fail if it is not passed the correct type for the args if they are statically typed, or passed an incorrect number of args. Ideally it should print something to console or error out if it's not able to call the function correctly, as it's difficult to figure out what's going wrong without that.

Steps to reproduce:

func test_me(val: String):
    print(val)

prints to console
get_tree().call_group("Test", "test_me", "test")

fails silently
get_tree().call_group("Test", "test_me", 0)
get_tree().call_group("Test", "test_me")

error 'Invalid call to function 'test_me (via call)' in base 'Node (script.gd)'. Expected 1 arguments.
call("Test", "test_me")

error 'Invalid type in function 'test_me (via call)' in base 'Node (script.gd)'. Cannot convert argument 2 from int to String.
call("Test", "test_me", 0)

@KoBeWi
Copy link
Member

KoBeWi commented Sep 18, 2019

I did some tests and standard call uses Variant::call, which errors properly, while using call_group does it via Object::call, which seems to be silent.

@Chinmaygoyal
Copy link

Can I work on this?

@KoBeWi
Copy link
Member

KoBeWi commented Oct 7, 2019

@Chinmaygoyal Sure, why not. There's no need to ask for permission.

@KoBeWi
Copy link
Member

KoBeWi commented Oct 28, 2020

After another look, this looks intended. When you call group, you call on multiple nodes and if it was throwing errors, you could potentially get lots of them on one call (like, you make a mistake and your debugger dies, because 1000 nodes got a wrong call). I think the proper way to "fix" this would be additional argument to optionally check if calls succeed or a warning when a call fails.

EDIT:
btw still valid in 3.2.3

@Lippanon
Copy link

Still valid in v4.4.dev.custom_build [6681f25]

With the addition of typed Dictionaries and Arrays this can be particularly confusing, because they are sometimes implicitly converted, seemingly, and sometimes not (such as arguments of a function).

Consider:

var dict :Dictionary = {1: Vector2i(1,2)}
var dict2 :Dictionary[int, Vector2i] = {1: Vector2i(1,2)}
var dict3 :Dictionary = dict2.duplicate(true)
print(dict.is_typed()) # false
print(dict2.is_typed()) # true
print(dict3.is_typed()) # true (implicit conversion ?)

However in this MRP, the call will silently fail:

extends Control

func _ready() -> void:
	add_to_group(&"test_group")
	
	var normal_dict :Dictionary = {0 : 1, 2 : 3}
	get_tree().call_group(&"test_group", &"test_1", normal_dict) # No error, no warning, silent fail
	
	var typed_dict :Dictionary[int, int] = {4 : 5, 6 : 7}
	get_tree().call_group(&"test_group", &"test_1", typed_dict)
	
	#test_1(normal_dict) # Prints error -> The dictionary of argument 1 (Dictionary) does not have the same element type as the expected typed dictionary argument.
	#test_1(typed_dict)

func test_1(arg_dict :Dictionary[int, int]) -> void:
	print("test 1 called")
	print(arg_dict)

typed dict bug.zip

Maybe it's not a bug, but I think if the function name is correct and exists then something should be shown to the user, because is there a case where you'd want to call the correct function name with wrong arguments?

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

Successfully merging a pull request may close this issue.

5 participants