-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
fixed pixelarray indexing to prevent segfault reported in #2275 #2276
fixed pixelarray indexing to prevent segfault reported in #2275 #2276
Conversation
Further note: |
I think this may be more complicated. If I create a PixelArray from a normal Surface and access the shape attribute, I get >>> weird_surface = pygame.Surface((0,5))
>>> pixarray = pygame.PixelArray(weird_surface)
>>> pixarray.shape
(0, 5)
>>> pixarray[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: array index out of range So the problem is that the code is using 0 in |
Another thing I found was that when the 0d value is in the Y value, then the shape of the pixel array does not include the Y value at all... import pygame
test_surf1 = pygame.Surface((0, 5))
test_surf2 = pygame.Surface((5,0))
pixarr1 = pygame.PixelArray(test_surf1)
pixarr2 = pygame.PixelArray(test_surf2)
print(pixarr1.shape, pixarr2.shape) Outputs: Also, calling any magic method on the broken PixelArray will cause it to segfault. This means that the issue isn't only in the indexing. Furthermore, the make_surface method of the broken PixelArray will simply hang indefinitely. It also does not close with KeyboardInterrupt. I had to force quit the terminal... |
My most recent commit makes it impossible to create that pixelarray in the first place. I'll keep looking at how to solve the issue in a less strict way, but this should at least prevent any segfault conditions for now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
I think not being able to create an array of pixels for a surface with absolutely no pixels is a perfectly acceptable solution to this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks 👍
fixed pixelarray indexing to prevent segfault reported in #2275
fixes #2275