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

PixelArray raise error assigning sequence to pixel #2742

Merged
merged 1 commit into from
May 11, 2024

Conversation

ankith26
Copy link
Member

@ankith26 ankith26 commented Mar 7, 2024

fixes #2740

  • In the pixelarray module, any sequence (except tuple and pygame.Color) isn't considered a "color", but rather a pixel sequence
  • The segfault happens because the code expects a pixelarray upon subscripting for assignment, but receives an "integer color"

I am open to suggestions on how to improve the error message, can't think of something descriptive enough ATM.

@ankith26 ankith26 requested a review from a team as a code owner March 7, 2024 19:29
@ankith26 ankith26 force-pushed the ankith26-pixelarray-fix branch from 69c7fc4 to ad298d6 Compare March 10, 2024 16:34
@yunline yunline added PixelArray pygame.PixelArray bugfix PR that fixes bug labels Mar 20, 2024
Copy link
Member

@oddbookworm oddbookworm left a comment

Choose a reason for hiding this comment

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

I take it the segfault is reproducible? If so, I'd like to see a regression test

@ankith26 ankith26 force-pushed the ankith26-pixelarray-fix branch from ad298d6 to d9b14aa Compare March 27, 2024 04:57
@ankith26
Copy link
Member Author

Have added the regression test, thanks for pointing it out

@ankith26 ankith26 added this to the 2.5.0 milestone Apr 4, 2024
@ankith26 ankith26 force-pushed the ankith26-pixelarray-fix branch from d9b14aa to 90b4cb4 Compare April 21, 2024 07:57
Copy link
Member

@oddbookworm oddbookworm left a comment

Choose a reason for hiding this comment

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

LGTM!

@narilee2006
Copy link
Contributor

narilee2006 commented Apr 27, 2024

Why not convert the PyList to a PyTuple? No errors, no worries.

static int
_pxarray_ass_item(pgPixelArrayObject *array, Py_ssize_t index, PyObject *value)
{
    // Shortened code...

    if (PyList_Check(value))
        value = PyList_AsTuple(value);

@ankith26
Copy link
Member Author

That is a behaviour change that deviates from the specification of the pixelarray module. According to the docs:

For assignment, a tuple can only be a color. Any other sequence type is a sequence of colors.

Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@MyreMylar MyreMylar merged commit 3822a18 into main May 11, 2024
36 checks passed
@ankith26 ankith26 deleted the ankith26-pixelarray-fix branch May 11, 2024 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix PR that fixes bug PixelArray pygame.PixelArray
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segfault when setting a pixel with PixelArray
5 participants