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

proposed fix: set curr_src.h to bottom_height before drawing bottom edges / corners in SDL_RenderTexture9Grid #12118

Merged
merged 1 commit into from
Feb 2, 2025

Conversation

l-t-m-f
Copy link
Contributor

@l-t-m-f l-t-m-f commented Jan 29, 2025

(...in order to avoid issue where inadvertently using top height, if the npatch existed on a larger texture than the drawn edge, would cause too many pixels to be included in the bottom part of the render.)

Description

There is a bug currently with SDL_RenderTexture9Grid, its hard to notice.

Two (2) conditions are needed to trigger, that I noticed.

a) The 9Grid texture is larger in height than the full size of the 9Grid, for example, if there is empty space bellow due to the 9Grid being stored on a spritesheet (streaming texture in minimal reproduce provided).

b) The 9Grid texture has different top and bottom margins.

Then when drawing the 9Grid, top_height was inadvertently used as curr_src.h when drawing lower_left and lower_right, as well as bottom of the 9Grid, causing either extra pixels to be drawn (resulting in squished bottom part of the 9Grid) or cropped (haven't tested that second case). curr_src.h should have been set to bottom_height before these operations. If the 9Grid is stored on a perfectly sized texture, and top_height> bottom_height, then even if the issue was technically occuring, it wasn't having any visual impact due to the texture naturally "ending" when problem should arise...

Anyway, hope I make myself clear. The fix is pretty simple.

This is a minimal example which demonstrates the problem:
https://pastecode.io/s/pi5qo9o1

I used a 50x50 image with margins L=10, R=10, T=14, B=10, placed on a larger 100x100 sheet, which demonstrates the problem.
Image if you want to test it :
ngrid

…m edges / corners in SDL_RenderTexture9Grid, to avoid issue where inadvertently using top height if the npatch existed on a larger texture than the drawn edge would cause too many pixels to be included in the bottom part of the render.
@l-t-m-f l-t-m-f changed the title proposed fix: set curr_src.h is to bottom_height before drawing bottom edges / corners in SDL_RenderTexture9Grid proposed fix: set curr_src.h to bottom_height before drawing bottom edges / corners in SDL_RenderTexture9Grid Jan 29, 2025
@slouken slouken added this to the 3.2.2 milestone Jan 29, 2025
@slouken slouken merged commit c922762 into libsdl-org:main Feb 2, 2025
41 checks passed
@slouken
Copy link
Collaborator

slouken commented Feb 2, 2025

Merged, thanks!

@slouken
Copy link
Collaborator

slouken commented Feb 2, 2025

@Oen44, do you need this fix in #12076?

@Oen44
Copy link

Oen44 commented Feb 2, 2025

@Oen44, do you need this fix in #12076?

Yeah, I will add this there as well, it just makes sense.

Oen44 added a commit to Oen44/SDL that referenced this pull request Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants