My script worked initially, displaying a window as expected. However, subsequent runs result in a segmentation fault (zsh: segmentation fault /usr/local/bin/python3) without any Python errors. I tested another Python program (fibonacci) and it worked fine. Can anyone assist?
Here's my script:
import pygame as pg
from OpenGL.GL import *
class App():
def __init__(self):
# init python
pg.init()
self.clock = pg.time.Clock()
# init opengl
glClearColor(0.1, 0.2, 0.2, 1)
self.mainLoop()
def mainLoop(self):
running = True
while running:
# check events
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
# refresh
glClear(GL_COLOR_BUFFER_BIT)
pg.display
# timing
self.clock.tick(60)
self.quit()
def quit(self):
pg.quit()
if __name__ == "__main__":
myApp = App()
You have to create an OpenGL display with
pygame.display.set_modeusing thepygame.OPENGLflag: