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

RID as default value are empty in extension_api.json #64442

Closed
touilleMan opened this issue Aug 15, 2022 · 1 comment · Fixed by #78517
Closed

RID as default value are empty in extension_api.json #64442

touilleMan opened this issue Aug 15, 2022 · 1 comment · Fixed by #78517

Comments

@touilleMan
Copy link
Member

Godot version

4.0-rc13

System information

n/a

Issue description

RID as default value are not serialized properly, for instance PhysicsServer2D::joint_make_pin

{
	"name": "joint_make_pin",
        [...]
	"arguments": [
		{
			"name": "joint",
			"type": "RID"
		},
		{
			"name": "anchor",
			"type": "Vector2"
		},
		{
			"name": "body_a",
			"type": "RID"
		},
		{
			"name": "body_b",
			"type": "RID",
			"default_value": ""  # <== ?????
		}
	]
},

This is because Variant::get_construct_string is use for the serialization which doesn't support serialization of RID:

d3["default_value"] = default_args[dargidx].get_construct_string();

Variant::get_construct_string doesn't support serialization of RID and default to an empty string:

default: {
}

The main issue

We represent the default value in ClassDB as an instance of RID which doesn't tell us we don't care about this instance (i.e. the default value is in fact "a new instance of RID is going to be created each time you call the function")

I think the easier solution would be to add a workaround in extension_api_dump.cpp (typically adding "RID()" as default_value if the argument type is RID and it has a default value set).

Of course this is not perfect given this way extension_api.json also don't provide the "this default value should be generated before each use". However we can fix this by adding a reusable_default_value boolean flag (that would only be true for RID).

Bonus issue

I'm not sure why Variant::get_construct_string doesn't serialize RID 🤔
It is also the case for Callable and Signal.

It means Dictionary/Array containing RID/Callable/Signal are not properly serialized as they will be displayed as [, , ,]

In the case this behavior is expected, shouldn't we add a warning when trying to serialize RID/Callable/Signal ?

Steps to reproduce

n/a

Minimal reproduction project

No response

@AThousandShips
Copy link
Member

AThousandShips commented Jun 22, 2023

Got a PR open for this, due to default serialization indeed

@akien-mga akien-mga added this to the 4.1 milestone Jun 22, 2023
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.

4 participants