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

Segfault when setting a pixel with PixelArray #2740

Closed
bilhox opened this issue Mar 6, 2024 · 1 comment · Fixed by #2742
Closed

Segfault when setting a pixel with PixelArray #2740

bilhox opened this issue Mar 6, 2024 · 1 comment · Fixed by #2742
Labels
bug Not working as intended

Comments

@bilhox
Copy link
Contributor

bilhox commented Mar 6, 2024

Original report : pygame/pygame#4163 (comment)

Environment:

Operating system: Linux / Windows (Endeavour)
Python version : 3.11.7
SDL version: 2.28.0+
PyGame version: 2.4.1
Current behavior:

Segfault when changing a pixel in a PixelArray with the syntax pixel_array[y][x].
Returns an error ValueError: sequence size missmatch with the syntax pixel_array[x, y].

Expected behavior:

Target pixel is set to the requested color in the PixelArray, as per documentation.

Test code

import pygame
test = pygame.Surface([800,800])
testBuf = pygame.PixelArray(test)
testBuf[400][400] = [255,255,0]

Stack trace/error output/other error logs

$ python3.11
Python 3.11.7 (main, Jan 29 2024, 16:03:57) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame-ce 2.4.0 (SDL 2.28.5, Python 3.12.0)
>>> test = pygame.Surface([800,800])
>>> testBuf = pygame.PixelArray(test)
>>> testBuf[400][400] = [255,255,0]
Segmentation fault (core dumped)
@bilhox bilhox added the bug Not working as intended label Mar 6, 2024
@ankith26
Copy link
Member

ankith26 commented Mar 7, 2024

Thanks for the issue, linked PR fixes the segfault.

As for your usecase, replacing [255, 255, 0] with (255, 255, 0) makes pixelarray interpret the object as a color and behave as you expect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants