0

Good morning guys, I have a problem with my code, I'm trying to draw a chessboard on pygame but I get this error and I don't know really how to solve it

pygame 2.1.2 (SDL 2.0.16, Python 3.10.4)
Hello from the pygame community. https://www.pygame.org/contribute.html
Fatal Python error: pygame_parachute: (pygame parachute) Segmentation Fault
Python runtime state: initialized

Current thread 0x00007f77e3750000 (most recent call first):
  File "/home/claudiosavelli/PycharmProjects/pythonProject1/main.py", line 34 in drawBoard
  File "/home/claudiosavelli/PycharmProjects/pythonProject1/main.py", line 25 in main
  File "/home/claudiosavelli/PycharmProjects/pythonProject1/main.py", line 37 in 

Extension modules: pygame.base, pygame.constants, pygame.rect, pygame.rwobject, pygame.surflock, pygame.color, pygame.bufferproxy, pygame.math, pygame.surface, pygame.display, pygame.draw, pygame.event, pygame.imageext, pygame.image, pygame.joystick, pygame.key, pygame.mouse, pygame.time, pygame.mask, pygame.pixelcopy, pygame.transform, pygame.font, pygame.mixer_music, pygame.mixer, pygame.scrap, pygame._freetype (total: 26)

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

This is my actual code, which is very simple so I don't know what the problem is:

    import pygame as p

WIDTH = 1080
HEIGHT = 720
BOARD_WIDTH = 448  # 64*7
BOARD_HEIGHT = 576  # 64*9
DIMENSION_ROW = 9
DIMENSION_COL = 7
SQUARE_SIZE = 64
MAX_FPS = 28
IMAGES = {}

MOVE_LOG_PANEL_WIDTH = 0

def main():
        p.init()
        screen = p.display.set_mode((WIDTH, HEIGHT))
        screen.fill(p.Color("purple"))
        running = True

        while (running):
            for e in p.event.get():
                if e.type == p.quit():
                    running = False
            drawBoard(screen)

        return

def drawBoard(screen):
    colors = [p.Color("white"), p.Color("gray")]
    for r in range(DIMENSION_ROW):
        for c in range(DIMENSION_COL):
            color = colors[((r + c) % 2)]
            p.draw.rect(screen, color, p.Rect(c * SQUARE_SIZE, r * SQUARE_SIZE, SQUARE_SIZE, SQUARE_SIZE))

if __name__ == "__main__":
    main()

1 Answers1

1

The event type is pygame.QUIT and not pygame.quit(). By testing if the event is equal to pygame.quit() in your if in your event loop, in fact you called pygame.quit() and destroyed all the pygame context. Replace this and it will work.

By the way, don't forget to call pygame.display.update() after drawing your rectangles if you want your changes to appear on the screen.

Exodeon
  • 23
  • 1
  • 5