Pygame error: surface mapping: why?

Can someone tell me why my application crashes with:

pygame error: Surface mapping completed.

+4
source share
6 answers

I had a similar problem, and I found that Surface objects do not like to be intaglio printed. When I used copy.deepcopy () on such an object and then accessed the copy, I got this strange error message (without calling pygame.quit ()). Maybe you experience this kind of behavior?

+10
source

From http://archives.seul.org/pygame/users/Nov-2006/msg00236.html :

On Thu, 2006-11-30 at 21:27-0300, Nicholas Bischof wrote:

pygame.error: display Surface completion what does this mean ?, I can’t fix it.

This means that the call was called pygame.display.quit () or pygame.quit (). If you try to do something on the surface of the display after you exit this error.

+1
source

I had a similar problem in a very simple piece of code:

import sys, pygame pygame.init() size = width, height = 640, 480 speed = [2, 2] black = 0, 0, 0 screen = pygame.display.set_mode(size) ball = pygame.image.load("Golfball.png") ballrect = ball.get_rect() while 1: event = pygame.event.poll() if event.type == pygame.QUIT: pygame.quit() ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right > width: speed[0] = -speed[0] if ballrect.top < 0 or ballrect.bottom > height: speed[1] = -speed[1] screen.fill(black) screen.blit(ball, ballrect) pygame.display.flip() pygame.time.delay(5) 

Error message:

  Traceback (most recent call last): File "<stdin>", line 1, in <module> File "bounce.py", line 22, in <module> screen.fill(black) pygame.error: display Surface quit 

So I put

  import pdb 

top after

  pygame.init() 

and used

  pdb.set_trace() 

after line with

  pygame.quit() 

Now I started the program, clicked to close the window, and actually was a little surprised to see that I got into the debugger (in the end, I expected that quitting smoking would completely take me out immediately). Therefore, I came to the conclusion that the throw does not really stop everything at that moment. It seems that the program continued beyond the exit, reached

  screen.fill(black) 

and it caused a problem. Therefore I added

  break 

after

  pygame.quit() 

and everything is working happily now.

[Added later: now it comes to me that

  pygame.quit() 

leaves the module, not the running program, so you need a break to exit this simple program. ]

For the record only, this means a good version

  import sys, pygame pygame.init() size = width, height = 640, 480 speed = [2, 2] black = 0, 0, 0 screen = pygame.display.set_mode(size) ball = pygame.image.load("Golfball.png") ballrect = ball.get_rect() while 1: event = pygame.event.poll() if event.type == pygame.QUIT: pygame.quit() break ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right > width: speed[0] = -speed[0] if ballrect.top < 0 or ballrect.bottom > height: speed[1] = -speed[1] screen.fill(black) screen.blit(ball, ballrect) pygame.display.flip() pygame.time.delay(5) 
+1
source

I had this problem too, and it looks like Maciej Miąsik answered me that it was related to copy.deepcopy () image.

I have had:

 import copy,pygame,sys from pygame.locals import * EMPTY_IMG= pygame.image.load('C:super/fancy/file/path/transparent.png') held_image=copy.deepcopy(EMPTY_IMG) my_rect=held_image.get_rect() my_rect.center = (50,50) screen.blit(held_image,my_rect) 

And I got the same error.

I just changed copy.deepcopy (EMPTY_IMG) only to EMPTY_IMG.

 import copy,pygame,sys from pygame.locals import * EMPTY_IMG= pygame.image.load('C:super/fancy/file/path/transparent.png') held_image=EMPTY_IMG my_rect=held_image.get_rect() my_rect.center = (50,50) screen.blit(held_image,my_rect) 

Then everything worked fine.

0
source

I also had this problem, but I got it from another source.

I had a class defined as follows:

 class PauseMenu(pygame.Surface) 

I got an error when I forgot to initialize pygame.Surface and tried to rekindle it by causing the pygame.screen error and gave me this error.

so I just added this obviously

 pygame.Surface.__init__(self, (width, height)) 
0
source
 import pygame, sys running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() # quit the screen running = False sys.exit() 

call sys.exit () after pygame.quit () to stop the program so that you cannot change the surface after you left pygame and did not receive an error

0
source

All Articles