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

[3.x] Make TextureButton and Button update on texture change #81113

Merged
merged 1 commit into from
Sep 7, 2023

Conversation

AThousandShips
Copy link
Member

Currently unable to verify functionality on 3.x builds, code should work but would appreciate someone verifying

@AThousandShips AThousandShips added bug needs testing topic:gui cherrypick:3.5 Considered for cherry-picking into a future 3.5.x release labels Aug 29, 2023
@AThousandShips AThousandShips added this to the 3.6 milestone Aug 29, 2023
@AThousandShips AThousandShips requested a review from a team as a code owner August 29, 2023 10:33
Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic slightly changes, as in 3.x we didn't check if (destination == p_texture) for TextureButton textures before. So with this change there won't be updates triggered if someone sets the exactly the same value to a member.

I think it should be fine though. And the code adaptation to 3.x LGTM.

scene/gui/button.cpp Outdated Show resolved Hide resolved
@AThousandShips
Copy link
Member Author

Can remove the check for same value as well if wanted to keep parity with 3.x, though the changes to TextureRect added such a check in #81100

@@ -343,6 +344,27 @@ void TextureButton::set_focused_texture(const Ref<Texture> &p_focused) {
focused = p_focused;
};

void TextureButton::_set_texture(Ref<Texture> *p_destination, const Ref<Texture> &p_texture) {
DEV_ASSERT(p_destination);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEV_ASSERT should only be used for bottleneck code. A regular check here won't matter.

But I think a better way is to pass by non-const reference, so we don't have to do any check.

Copy link
Member Author

@AThousandShips AThousandShips Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See: #77159 (comment)

Also DEV_ASSERT is for crashing, not performance critical AFAIK

Keeping the code as proven in 4.x for now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work, assigning to the reference won't update the texture itself

The referenced Ref object won't change. What will be updated is the content of that Ref, which is the texture.

Also DEV_ASSERT is for crashing, not performance critical AFAIK

A note was added recently:

* DEV_ASSERT should generally only be used when both of the following conditions are met:
* 1) Bottleneck code where a check in release would be too expensive.
* 2) Situations where the check would fail obviously and straight away during the maintenance of the code
* (i.e. strict conditions that should be true no matter what)
* and that can't fail for other contributors once the code is finished and merged.

But anyway, I think it's fine if the Godot 4 version uses this. I should have read the original PR, sorry :(

Copy link
Member Author

@AThousandShips AThousandShips Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, all the changes except to fit it to 3.x code are from the 4.x one, now minus the is_valid part

Checked in 4.x and passing by reference works there, but don't want any potential unseen side effects for a cheery pick, thank you for feedback

@akien-mga akien-mga merged commit b9aa89d into godotengine:3.x Sep 7, 2023
13 checks passed
@akien-mga
Copy link
Member

Thanks!

@AThousandShips AThousandShips deleted the texture_button_fix_3_x branch September 7, 2023 11:37
@AThousandShips
Copy link
Member Author

Thank you!

@akien-mga
Copy link
Member

Cherry-picked for 3.5.3.

@akien-mga akien-mga removed the cherrypick:3.5 Considered for cherry-picking into a future 3.5.x release label Sep 24, 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 this pull request may close these issues.

4 participants