Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Segfault in PixelArray when trying to access surface after closing the PixelArray #3665

@oddbookworm

Description

@oddbookworm

If you try to access the surface attribute of a PixelArray after you closed it, then pygame segfaults. Obviously you shouldn't grab the surface from a closed PixelArray, but it shouldn't segfault either.

MRE

import pygame
import pygame.pixelarray

screen = pygame.display.set_mode((500, 500))

surf = pygame.Surface((50, 50))
surf.fill("red")

def do_stuff():
    pixels = pygame.pixelarray.PixelArray(surf)
    pixels.close()
    screen.blit(pixels.surface, (0, 0))

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    
    screen.fill("black")
    print("crashes now")
    do_stuff()
    pygame.display.flip()

(Windows 11, Python 3.11.1, pygame 2.1.3dev8)
(Windows 11, Python 3.11.1, pygame 2.1.4dev1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions