I had a little play with this, and the following segfaults, too (on OS X 10.7 w/ Macports Python 2.7 and pygame 1.9.1)
import pygame import io pygame.font.init() f = open("/opt/local/share/wine/fonts/symbol.ttf", "r") font = pygame.font.Font(f, 8) # Works fine f.close() f = open("/opt/local/share/wine/fonts/symbol.ttf", "rb") buffer = io.BytesIO() c=f.read() print(len(c)) while len(c) != 0: buffer.write(c) c=f.read() print(len(c)) f.close() buffer.seek(0) font = pygame.font.Font(buffer, 8) # Segfault Similarly with StringIO.StringIO() Russell On 1 January 2012 10:50, Radomir Dopieralski <pyg...@sheep.art.pl> wrote: > Hello everyone, > > I'm having a problem loading a font file from a python file-like > object. According to the documentation at > http://www.pygame.org/docs/ref/font.html#pygame.font.Font this should > be possible, however, I get a segmentation fault every time I pass a > file-like object that is not created by opening a real file. I want to > load all my assets from a zip archive, so it's not possible to have a > real file in the filesystem. > > A simple test case: > > import pygame > import StringIO > > pygame.font.init() > > f = open("somefont.ttf", "r") > font = pygame.font.Font(f, 8) # Works fine > f.close() > > f = open("somefont.ttf", "r") > buffer = StringIO.StringIO(f.read()) > f.close() > font = pygame.font.Font(buffer, 8) # Segfault > > Is there any way to make it work as documented? If the documentation > is wrong, is there any way to create a pygame font object without > creating a real file in the filesystem? > > Thanks, > -- > Radomir Dopieralski >