使用fill(color)方法时pygame崩溃 [英] pygame crashes when fill(color) method is used

查看:133
本文介绍了使用fill(color)方法时pygame崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用fill()方法时,我的pygame代码崩溃.

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

首先,我发现有一个完全相同的问题这个网站的其他人可能和我看过相同的pygame教程,但是问题实际上并没有在那里解决,这就是为什么我要创建这个重复的问题(并不是真正的重复,因为其他人最初提出的问题不是也没有解决).

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).

我的代码在下面.导致崩溃的代码部分是GameDisplay.fill(black)部分.

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

我知道这一点,因为当我删除该行时,一切正常.我的pygame版本与我拥有的python(2.7)相同,均为32位.我使用的设备是macbook air.

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.

我已经尝试过重新安装python和pygame,但是代码仍然会崩溃.我只有一台Macbook,不能像问同样问题的其他人那样在Windows计算机上执行此操作,因此我想知道是否还有其他方法可以使这项工作正常进行?帮助将不胜感激!

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()

推荐答案

我在Macbook Air上遇到了完全相同的问题. Pygame可以创建一个屏幕,但是无论何时尝试触摸它,它都会崩溃并出现细分错误(这是您在错误中看到的SIGSEGV).这是因为Pygame依赖于SDL框架,而Mac上的内置框架...并不完美.

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.

从SDL官方网站上,转到下载页面,并获取运行时库适用于Mac的1.2.15.打开下载的.dmg文件,您将获得一个SDL.framework文件.在Finder中打开/Library/Frameworks并将框架文件移到那里. (如果它要求替换,我选择了合并",但我确定替换"也可以使用.)

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.)

这为我修复了Pygame.我希望它也对您有用!

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

这篇关于使用fill(color)方法时pygame崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆