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 canvas rect bound calculation #49160

Merged
merged 1 commit into from
May 31, 2021

Conversation

lawnjelly
Copy link
Member

@lawnjelly lawnjelly commented May 28, 2021

It turns out the calculation of the bounding rect for canvas items has a nasty bug. When a transform is applied (especially in a custom draw), in the renderer this extra matrix is applied to all later commands in the canvas item. However in the calculation of the bound, the transform is only applied to the first command following the transform.

This PR fixes this inconsistency.

Fixes #49156

Notes

  • Amazingly, this bug has existed since at least 3.1, possibly a lot further back. It may not have been noticed as people use custom drawing a lot less than the default canvas types.
  • Have tested on a few projects, seems to work fine. More testing welcome though.
  • It may be needed in Godot 4.x also.

It turns out the calculation of the bounding rect for canvas items has a nasty bug. When a transform is applied (especially in a custom draw), in the renderer this extra matrix is applied to all later commands in the canvas item. However in the calculation of the bound, the transform is only applied to the first command following the transform.

This PR fixes this inconsistency.
@lawnjelly lawnjelly requested a review from a team as a code owner May 28, 2021 07:49
@Chaosus Chaosus added this to the 3.4 milestone May 28, 2021
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Makes sense to me!

I think reduz will have to double check as well. There may be a reason he only applied the transform to one command.

@lawnjelly
Copy link
Member Author

Yeah I agree to get reduz to take a look to confirm. It could have been that originally the transform did apply to just the first command, but looking at the code, I suspect it is just a late night bug that never got caught.

@lawnjelly lawnjelly requested a review from reduz May 28, 2021 15:41
@akien-mga akien-mga merged commit b2059ca into godotengine:3.x May 31, 2021
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

It may be needed in Godot 4.x also.

The same code seems to exist in servers/rendering/renderer_canvas_render.h indeed, would you make a PR for it?

@lawnjelly
Copy link
Member Author

lawnjelly commented May 31, 2021

It may be needed in Godot 4.x also.

The same code seems to exist in servers/rendering/renderer_canvas_render.h indeed, would you make a PR for it?

Already done. 👍
#49161

@akien-mga
Copy link
Member

Cherry-picked for 3.3.3.

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.

6 participants