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

Correct RichTextLabel.custom_effects property type metadata #40383

Conversation

touilleMan
Copy link
Member

Current entry in api.json:

{
	"name": "custom_effects",
	"type": "17/17:RichTextEffect",
	"getter": "get_effects",
	"setter": "set_effects",
	"index": -1
},

I couldn't figure out the meaning of 17/17:RichTextEffect and didn't see any other places where this is used.

The correction mimic what is done in RDPipelineColorBlendState::attachments:

ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "attachments", PROPERTY_HINT_ARRAY_TYPE, "RDPipelineColorBlendStateAttachment"), "set_attachments", "get_attachments");

@akien-mga akien-mga added bug cherrypick:3.x Considered for cherry-picking into a future 3.x release topic:gui labels Jul 15, 2020
@akien-mga akien-mga added this to the 4.0 milestone Jul 15, 2020
@akien-mga akien-mga merged commit f337dd3 into godotengine:master Jul 15, 2020
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

akien-mga commented Jul 15, 2020

Cherry-picked for 3.2.3. Edit: Reverted.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jul 15, 2020
@akien-mga
Copy link
Member

Undid the cherry-pick, there are no typed arrays in 3.2.

@EricEzaM
Copy link
Contributor

EricEzaM commented Jun 21, 2021

Unfortunately this broke things. I agree the syntax in the ADD_PROPERTY() is bad with the slash and the colon, but this is not the way to solve it.

Anyway, this broke customising of effects in RichTextLabel. This is the only place an Array of Resource type is used, until I needed to do the same thing, which led me down the rabbit hole to find this bug.

17/17 corresponds to PROPERTY_HINT_RESOURCE_TYPE and Variant::OBJECT (which were both enum value 17 at the time). This was used here:

void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint_string) {
array_type = p_array_type;
if (array_type == Variant::ARRAY && !p_hint_string.is_empty()) {
int hint_subtype_separator = p_hint_string.find(":");
if (hint_subtype_separator >= 0) {
String subtype_string = p_hint_string.substr(0, hint_subtype_separator);
int slash_pos = subtype_string.find("/");
if (slash_pos >= 0) {
subtype_hint = PropertyHint(subtype_string.substr(slash_pos + 1, subtype_string.size() - slash_pos - 1).to_int());
subtype_string = subtype_string.substr(0, slash_pos);
}
subtype_hint_string = p_hint_string.substr(hint_subtype_separator + 1, p_hint_string.size() - hint_subtype_separator - 1);
subtype = Variant::Type(subtype_string.to_int());
}
}
}

See all those slices looking for : and /... yeah... that is where it was used.

The PROPERTY_HINT corresponds to the sub-type, meaning RichTextEffect. The type of the property itself is already defined as Variant::ARRAY. So saying PROPERTY_HINT_ARRAY is wrong. It was correct in being PROPERTY_HINT_RESOURCE_TYPE, although ironically that value was not used, instead the "17"'s in the string were used...

Previously when you opened the menu for custom effects, you would only see this:
image

After this change, you would see the whole list because the editor did not know what to do.
image

This begs the question... did you test the changes before submitting the PR? If you built, ran and tested before submitting you would have seen that the custom_effects property was broken after your change, and known that something went wrong. Doesn't take long to test, and would have saved me a truckload of time 1 year down the line, finding the issue. Especially considering that the syntax of the hint string was so abstract and strange, I think it should have raised red flags that it was like that for a reason.

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.

3 participants