[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pygame] font.c is broken for unicode in pygame 1.5.2 and above



Hi all -

I'm new to the list. I thought I would post this in an attempt to help out pygame development and help others avoid the pain I just went through.

I had a large body of code using pygame that mysteriously quit working on me after I upgraded to RedHat 8.0. At first I blamed the upgrade, then found that pygame crashed in the same way on Windows 2000 and on Windows XP.

To make a long story short, I discovered that the changes in font.c between pygame 1.5 and pygame 1.5.2 were to blame. The following 35-line script works on pygame 1.5 but crashes with a Segmentation fault (memory access violation) on pygame 1.5.2:

----- begin code -----
# isolate crashing bug
import pygame
import pygame.locals

# create main window
pygame.init()
pygame.display.set_mode((320,240))
pygame.display.set_caption("Crash debug")
# set up text output
screen = pygame.display.get_surface()
font = pygame.font.Font(None, 25)

def write(s, loc):
xsize, ysize = font.size(s)
text = font.render(s, 1, (224, 224, 128), (32, 32, 128))
rect = screen.blit(text, loc)
return rect

# attempting to write the digits 0 through 9 will cause a crash
cur_line = u''
for i in range(10):
s = str(i)
s = unicode(s, 'utf-8')
pygame.display.update([write(s, (i*25, 0))])
cur_line = u"%s%s" % (cur_line, s)

# event loop
while 1:
e = pygame.event.wait()
if e.type == pygame.locals.QUIT:
break

pygame.quit()

# end-of-file
----- end code -----

On a hunch that font rendering code was to blame, I transplanted font.c from the pygame 1.5 source to the 1.5.2 source, recompiled, and tested. My test script ran fine after that, and so did the rest of my code.

There were two places in font.c where the problems just jumped out at me, and I emailed a patch to Pete at pete@shinners.org on Thursday (2 days ago.) However, that patch did not fix all of the problems, and did not cause the script above to be able to run correctly. Using the font.c from pygame 1.5 did fix all my known problems.

Is this the correct forum for reporting and resolving problems like this?

Thanks for looking at this -

David H

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org