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

查看:14
本文介绍了使用填充(颜色)方法时,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 网站,转到 下载页面 并获取运行时库1.2.15 为 Mac.打开您下载的 .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!

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

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