1

I'm using python 2.7.10 and pygame 1.9.1 on OS X 10.11.1

I'm getting Segmentation fault: 11 & python crashes whenever I draw anything on or fill a pygame surface (at least I think that's the cause). I have several pygame projects I've done for school that have worked on this same machine in the past, but simply crash now. I don't recall changing python or pygame versions since then, only updating OS X version.

This is a simple little program that should just display a red rectangle on a purple-ish background:

import pygame
import pygame.locals

class ExampleClass:
    def __init__(self):
        self.screen = pygame.display.set_mode(
                        (100, 100),
                        pygame.locals.DOUBLEBUF |
                        pygame.locals.SRCALPHA)


    def paint(self, surface):
        surface.fill((100, 50, 255))        # blue-purple-y background
        pygame.draw.rect(surface, (255, 50, 100), (10, 10, 50, 25))     # red rectangle

    def main_loop(self):
        clock = pygame.time.Clock()

        while True:
            clock.tick(30)

            for e in pygame.event.get():
                if e.type == pygame.QUIT:
                    pygame.quit()
                    return
                if e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
                    pygame.quit()
                    return

                self.paint(self.screen)

                pygame.display.flip()

example = ExampleClass()
example.main_loop()

I tried this on a windows machine & it worked completely fine, however it crashes on my mac. If you comment out self.paint(self.screen), the window pops up & there's no crash. I've searched around a bit and not found much. I have no idea what's causing it to do this, any help would be greatly appreciated.

  • I think you need to call `pygame.init()` at the beginning. – DJMcMayhem Dec 14 '15 at 23:31
  • @DJMcMayhem I just tried it, it doesn't seem to do anything. I never had that in any of my prior projects & they all worked at one point. This same code also works fine on windows, so I don't think that's the problem... – Pencil Frog Dec 14 '15 at 23:50

1 Answers1

1

I know this is old, but it's a bug in the built in SDL library.

Download the SDL-1.2.15 lib for Mac from the official site

Ilario Pierbattista
  • 3,175
  • 2
  • 31
  • 41