Hein de Wilde
Hein de Wilde

Reputation: 197

Segmentation fault: 11 when trying to run Pygame

I am using OSX 10.11.6, Python 2.17.12 and Pygame 1.9.1. I made this simple program that should display a black rectangle in the middle of a white field. However, when I try to run it I get an error saying:

Segmentation fault: 11

I have tried several things, but nothing seems to work. Here is my code:

import pygame

pygame.init()

white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)

gameDisplay = pygame.display.set_mode((800, 600))
pygame.display.set_caption('Slither')

gameExit = False

while not gameExit:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
        gameExit = True

    gameDisplay.fill(white)
    pygame.draw.rect(gameDisplay, black, [400, 300, 20, 20])

    pygame.display.update()

pygame.quit()
quit()

Does someone know how I can solve this issue? Thanks in advance! Note: I am writing my code in Atom, and running it in Terminal using this command:

$ python2.7-32 slither.py

Upvotes: 0

Views: 930

Answers (1)

numbermaniac
numbermaniac

Reputation: 788

This is due to a flaw in the built-in SDL library that Pygame depends on. Pygame can create a screen, but attempting to touch it will immediately crash it with Segmentation error 11.

From the official SDL website, go to the download page and get the runtime library 1.2.15 for Mac. Open the .dmg you downloaded and you'll be given an SDL.framework file. Open /Library/Frameworks in Finder and move the framework file there. You may need to select Replace.

Upvotes: 1

Related Questions