[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pygame] Script crashes with Fatal Python error: (pygame parachute) segfault
- To: pygame-users <pygame-users@seul.org>
- Subject: [pygame] Script crashes with Fatal Python error: (pygame parachute) segfault
- From: "Mike C. Fletcher" <mcfletch@rogers.com>
- Date: Tue, 28 May 2002 22:03:29 -0400
- Delivered-To: archiver@seul.org
- Delivered-To: pygame-users-outgoing@seul.org
- Delivered-To: pygame-users@seul.org
- Delivery-Date: Tue, 28 May 2002 22:03:31 -0400
- Reply-To: pygame-users@seul.org
- Sender: owner-pygame-users@seul.org
- User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0rc1) Gecko/20020417
Hi all,
No clue why this is happening, the code seems perfectly fine (and
simple). Commenting out a tuple of 0's and 1's getting added to a
dictionary avoids the segfault. I'm assuming there's a memory
management problem somewhere (possibly 0 or 1 getting garbage collected?)
Problem is seen with 1.4.9 downloaded a few minutes ago running against
Python 2.2. The traceback says that it's occuring on the line (around 68):
for x,y in self.charmap.items():
data.append( '%s:%s,\n'%( repr(x),repr(y)))
With x being a simple character and y being a tuple of (integer,
integer, (0,0,1,1)). The last item eventually will hold the mapping
coordinates (floating point values) into a larger bitmap.
Any thoughts or pointers appreciated.
Mike
Here's the offending code (it's a simple script to generate fonts for
use with PyOpenGL w/out the need to have PyGame available on the target
system).
8<____________ font2.py ____________
import pygame
from pygame.locals import *
from pygame.font import *
from pygame.image import *
from pygame import *
pygame.init()
class Compiler:
"""Uses PyGame/SDL to generate a "compiled" font for use with
PyOpenGL"""
def __init__(
self, filename=None, pixelSize=12, colour= (255,255,255),
bold=0, italic=0, underline=0, antialias = 1,
):
self.name = filename
self.colour = colour
self.pixelSize = pixelSize
self.bold = bold
self.italic = italic
self.underline = underline
self.antialias = antialias
self.bitmaps = []
self.charmap = {
}
def generate( self, characters = [chr(x) for x in range(0,256)]):
"""Generate glyph entries for each character in characters"""
font = Font( self.name, self.pixelSize )
font.set_bold( self.bold )
font.set_italic( self.italic )
font.set_underline( self.underline )
for character in characters:
try:
surface = font.render(
character,
self.antialias,
self.colour
)
except error:
print 'fail character', repr(character), ord(character)
surface = font.render(
" ",
self.antialias,
self.colour
)
width, height = surface.get_size()
imageData = image.tostring(surface, 'RGBA', 1)
# XXX do blit into a shared bitmap here...
# for now, each character has its own bitmap!
# coordinates are 0,0,1,1 because of that
# and the bitmap is just the bitmap we're adding
self.bitmaps.append( imageData )
self.charmap[ character ] = (
int(width),
len(self.bitmaps)-1,
## Uncommenting this line causes the pygame crash :(
## looking as though 0, or 1 is being destroyed?
(0,0,1,1)
)
def tostring( self ):
"""Return this font as a string for instantiation"""
data = []
for x,y in self.charmap.items():
data.append( '%s:%s,\n'%( repr(x),repr(y)))
characterMap = ",\n".join( data )
return """Font(
name = %s,
pixelSize = %s,
colour = %s,
bold = %s,
italic = %s,
underline = %s,
antialias = %s,
bitmaps = [
%s
],
charmap = {
%s
}
)"""%(
self.name, self.pixelSize, self.colour,
self.bold, self.italic, self.underline, self.antialias,
",\n".join(map(repr, self.bitmaps)),
characterMap,
)
if __name__ == "__main__":
s = Compiler()
s.generate()
print 'finished generation'
open( 'test.py', 'w').write( s.tostring())
print 'finished writing'
--
_______________________________________
Mike C. Fletcher
http://members.rogers.com/mcfletch/
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org