非法指令:在MacOS High Sierra上为4 [英] Illegal instruction: 4 on MacOS High Sierra

查看:108
本文介绍了非法指令:在MacOS High Sierra上为4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在pygame 3.6中创建一个看起来像聊天的窗口,我刚刚将MacBook更新到10.13.6版,在此之前它运行良好,但是得到了以下信息:非法指令:4.
代码

I am trying to make a chat-looking window in pygame 3.6, I just updated my MacBook to version 10.13.6, before I did this it worked perfectly but after I get the message: Illegal instruction: 4.
Code

import pygame
from pygame.locals import *
import pygame.gfxdraw

pygame.init()

window_width=360
window_height=640
animation_increment=10
clock_tick_rate=20
size = (window_width, window_height)
screen = pygame.display.set_mode(size)
black = (0,0,0)
grey = (220,220,220)
shadow = (0, 255, 0, 100)

pygame.display.set_caption("BrAIn")

dead=False

clock = pygame.time.Clock()
background_image = pygame.image.load("background.png").convert()
micro = pygame.image.load("microphone.png")
PF = pygame.image.load("BrAIn.png")


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

    font = pygame.font.Font("Impact copy.ttf", 52)
    text = font.render('BrAIn', True, (0,0,0))

    screen.blit(background_image, [0, 0])
    pygame.gfxdraw.hline(screen, 0, 360, 40, shadow)
    pygame.draw.line(screen, black, [0,62], [360,62], 2)
    pygame.draw.line(screen, grey, [0,30], [360,30], 62)
    pygame.draw.line(screen, grey, [0,620],[360,620],75)
    pygame.draw.line(screen, black, [0,583], [360,583], 2)
    screen.blit(micro, [152, 587])
    screen.blit(PF, [-5, -7])
    screen.blit(text, [125,0])

    pygame.display.flip()
    clock.tick(clock_tick_rate)


运行此命令后,Python 3.6(和2.7)也会崩溃.


Python 3.6 (and 2.7) also crashes after running this.

推荐答案

虽然删除pygame.init()"并不是一个真正的答案,但我想知道为什么这样做和如何永久解决此问题,我找到了一种解决"此问题的方法.我删除了pygame.init()命令,该命令给了我错误:pygame.error: font not initialized.这很明显,因为那时您还没有初始化字体所在的引擎.还有一种不使用pygame.init()而不出现此错误的方法(正如我中许多人所知道的那样),这是通过使用pygame.font.init()来实现的.我尝试用pygame.font.init()替换pygame.init(),最后我的程序像以前一样工作.我仍然非常想知道为什么以及如何产生此错误,如何永久消除该错误,以及pygame.font.init()pygame.init()之间有什么区别,但这对我来说是个暂时的答案.

Although "removing pygame.init()" isn't really much of an answer and I would like to know why it does this and how to permanently fix this, I have found a way to 'fix' this problem. I removed the pygame.init() command, which gave me the error: pygame.error: font not initialized. This is pretty obvious because then you haven't initialized the engine where the fonts are. There is another way without using pygame.init() without getting this error (as many of you are aware I think), this is by using pygame.font.init(). I tried replacing pygame.init() by pygame.font.init() and finally my program worked like it used to. I would still very much like to know why and how this error is made, how to permanently get rid of it and what difference there is between pygame.font.init() and pygame.init() but this is a temporary answer for me.

这篇关于非法指令:在MacOS High Sierra上为4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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