简体   繁体   中英

Pygame keeps making the kernel exit

So I was trying to display text on a screen using pygame. It works however after the third or fourth execution using pyzo, the kernel just exits and I have to restart it again. It is quite unstable and annoying.

I wonder about what I could have forgotten or did wrong. I am thankful to anyone taking the time to look at this problem.

Edit :

The error being: The kernel process exited. (3221225477)

running = True
while running :
    # completely fill the surface object 
    # with black color 
    display_surface.fill(black) 

    # copying the text surface object 
    # to the display surface object 
    # at the center coordinate. 
    update_text_screen(text_to_display)

    # iterate over the list of Event objects 
    # that was returned by pygame.event.get() method. 


    for event in pygame.event.get() : 
        if event.type == pygame.QUIT:
            running = False

    pygame.display.update()

pygame.display.quit()
pygame.quit()
class text:
    def __init__(self, message, colour, state, X, Y) :
        global text_to_display
        self.text_to_print = font_text.render(message, True, colour)
        self.X = X
        self.Y = Y
        self.state = state

    def v(self):
        display_surface.blit(self.text_to_print,[self.X,self.Y])



def update_text_screen(list_of_text):
    global C_px, C_py
    for i in range(len(list_of_text)) :
        if list_of_text[i].state:
            C_py = i*30
            list_of_text[i].X = C_px
            list_of_text[i].Y = C_py
        list_of_text[i].v()

Edit2 : Here's the bit of code asked by Valentino

I have exactly the same problem and it seems to disappear when I remove text drawing! So, after some tests, it seems to work when I delete the font object at the end of the program like this:

fontobj= pygame.font.SysFont("Arial", 25)
...
while ...
  ...
del(fontobj)
pygame.quit()

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM