[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Problem: read_unix_fontsdir failure on empty fonts.scale



I'm a volunteer for the Archy project
(http://rchi.raskincenter.org/aboutrchi/index.php).

I've got a bug
http://raskincenter.org/cgi-bin/roundup.cgi/issues/issue191
when user complained on failure due to exception in
read_unix_fontsdir. Later the user mentioned that the
cause of the problem was an empty fonts.scale file.
Wonder if pygame can provide more robust handling of
fonts directory with e.g. something like following:
***************************
--- lib/sysfont.py	15 Aug 2005 01:54:48 -0000	1.20
+++ lib/sysfont.py	17 Aug 2005 13:58:19 -0000
@@ -149,7 +149,10 @@ def read_unix_fontscache(dir,
file, font
 #read the fonts from a unix 'fonts.dot' file
 def read_unix_fontsdir(dir, file, fonts):
     file = open(os.path.join(dir, file))
-    numfonts = int(file.readline())
+    try:
+        numfonts = int(file.readline())
+    except ValueError:
+        return
     for line in file.readlines():
         font, descr = (line.split(' ', 1) + ['',
''])[:2]
         if font[-4:].lower() not in [".ttf", ".ttc"]:

***************************
(hope line wraps won't mess with understanding of the
patch).

You can also consider resolving it on higher level -
not just to check on file existence font files in
_fontwalk but making sure the file was loaded
correctly.
Please make sure problems with other files can't break
the library.

Thanks,
Andriy

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com