You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a 0-by-0 surface is passed as an argument to pygame.transform.gaussian_blur(), it raises the following exception:
ValueError: Blur routines do not support dest_surfaces that share pixels with the source surface. Likely the surfaces are the same, one of them is a subsurface, or they are sharing the same buffer.
This is doubly misleading because:
It doesn't help the user solve the actual problem (a size-zero surface as an argument)
It misleadingly directs the user to a specific keyword argument that is not part of the issue, which they might not even be using
This also happens for any surface with 0 as only one of its dimensions (10x0, 0x30).
Don't raise an exception. If a 0-by-0 surface is passed in, just return a new 0-by-0 surface through a copy or similar.
Raise a ValueError with a different error message that specifically mentions the dimensions of the surface argument.
I'd probably personally prefer #1, since it's less likely to cause errors in code flows that might produce surfaces of variable (and sometimes zero) size, and it's a fairly intuitive way to handle size-zero surfaces. I encountered this after trying to blur the output of Pygame.font.Font.render() for an empty string.
The text was updated successfully, but these errors were encountered:
I didn’t even think it was possible to construct a surface with a zero dimension
It certainly isn't useful most of the time --- but lots of existing surface operations handle it gracefully and as expected (usually doing nothing).
The big one is probably pygame.font.Font.render() which you might want to draw nothing when a string is empty (such as a user not having typed anything in a text box yet). It currently returns a 0x0 surface when given an empty string.
Environment:
Current behavior:
When a 0-by-0 surface is passed as an argument to
pygame.transform.gaussian_blur()
, it raises the following exception:ValueError: Blur routines do not support dest_surfaces that share pixels with the source surface. Likely the surfaces are the same, one of them is a subsurface, or they are sharing the same buffer.
This is doubly misleading because:
This also happens for any surface with 0 as only one of its dimensions (10x0, 0x30).
Code snippet to test this behavior:
Expected behavior:
Two potential fixes:
I'd probably personally prefer #1, since it's less likely to cause errors in code flows that might produce surfaces of variable (and sometimes zero) size, and it's a fairly intuitive way to handle size-zero surfaces. I encountered this after trying to blur the output of
Pygame.font.Font.render()
for an empty string.The text was updated successfully, but these errors were encountered: