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 division by zero in aspect ratio calculation #93764

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

patwork
Copy link
Contributor

@patwork patwork commented Jun 30, 2024

Info

Fixes #93738

A simple approach that protects against division by zero. When local_rect.has_area() returns false, i.e. width or height (or both) is zero, the aspect ratio calculation is performed on values incremented by 1.

In other cases, division is performed on the original values because (example):

  • 50.0 / 100.0 = 0.5
  • (50.0 + 1.0) / (100.0 + 1.0) = 0,504950495049505

Notes

By the way, it appears that the object resizing algorithm does not update the current dimensions for aspect ratio calculation when the shift key is pressed. This results in the shape not being adjusted to the current dimensions but to the original ones from the start of the dragging.

@Calinou Calinou added this to the 4.3 milestone Jun 30, 2024
Copy link
Contributor

@anniryynanen anniryynanen left a comment

Choose a reason for hiding this comment

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

I reproduced the issue and confirm that this PR fixes it.

I think the approach is good and it shouldn't be at risk of causing other bugs. I might change the increment to a bigger number, now if a control has say, size (0, 50), starting to scale the width up from 0 makes the height quickly go offscreen. (Edit: Scratch that, it'd quickly go offsceen for (1, 50) too.)

@JekSun97
Copy link

I also confirm that this solves my problem.

@akien-mga akien-mga merged commit f9474f0 into godotengine:master Jul 29, 2024
18 checks passed
@akien-mga
Copy link
Member

Thanks!

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.

Error spam when measuring the size of control nodes while holding the Shift button
5 participants