pygame crashes when fill(color) method is used


元气小坏坏 提交于 2019-12-17 20:53:19

问题


My pygame code crashes somehow when I use the fill() method.

First off I found there is an exact same question on this website by some one else who probably watched the same pygame tutorial as I did, but the problem is not actually solved on there and that's why I'm creating this duplicate question (not really a duplicate since the original question asked by someone else wasn't solved either).

My code is down below. The part of code that is causing the crashing is the GameDisplay.fill(black) part.

I know this, because when I delete that line everything works fine. My pygame version is the same as the python I have (2.7), and both are 32 bit. The device I'm using is a macbook air.

I have already tried reinstalling my python and pygame, but the code would still crash. I only have a macbook and cannot do this on a windows computer like the other guy who asked the same question, so I am wondering if there are anyways to make this work? Help will be appreciated!

import pygame

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

pygame.init()
GameDisplay = pygame.display.set_mode((800, 600))
pygame.display.set_caption("rooms")

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

    GameDisplay.fill(black)
    pygame.display.update()

pygame.quit()
quit()

回答1:


I had the exact same problem on my Macbook Air. Pygame can create a screen, but whenever it tries to touch it, it will crash with a Segmentation error (this is the SIGSEGV you see in your error). This is because Pygame relies on the SDL framework, and the built-in one on Mac is ... not perfect.

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. (If it asks to replace, I selected Merge, but I'm sure Replace should also work.)

This fixed Pygame for me. I hope it works for you too!



来源:https://stackoverflow.com/questions/37221463/pygame-crashes-when-fillcolor-method-is-used

工具导航Map