2

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 (and 2.7) also crashes after running this.

Luc Angevare
  • 25
  • 4
  • 17
  • 1
    Just to confirm, you are only getting this message with this python script and not others? Binaries compiled with older versions of MacOS can cause this problem. See: https://stackoverflow.com/questions/14268887/what-is-the-illegal-instruction-4-error-and-why-does-mmacosx-version-min-10 – Alan Williams Oct 06 '18 at 18:05
  • Yeah, it's only with Python, I tried C++, HTML (don't know why I tried that seen that runs on browser), and I tried C. They all worked except for Python 2.7.13 and Python 3.6.7. Also almost every module works exc for pygame. I tried uninstalling and reinstalling it but seen this is a problem with Macintosh I didn't expect it to work. – Luc Angevare Oct 07 '18 at 07:42
  • 1
    I just narrowed the error down, if I remove the `pygame.init()` command, (although it gives me other related errors) it stops giving me the `Illegal instruction: 4` error... Don't know what this means though. And yes, it is only this script (I have no other script that really uses pygame so... I can't really check if it has to do with pygame. Thanks in advance! – Luc Angevare Oct 07 '18 at 14:00
  • I just added some more text and it crashed... Again. – Luc Angevare Oct 08 '18 at 15:42

1 Answers1

1

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.

Luc Angevare
  • 25
  • 4
  • 17