Search code examples
pythonsegmentation-faultpygamecx-freeze

Pygame and cx_freeze: segmentation fault


I'm using ubuntu and python 2.6

I found cx freeze already installed on my system (is it there a way to check if it's compatible with my Python version? )

however, i have a small pygame script (which import another module and some images) and i want to compile it;

i used this file as setup.py:

#!/usr/bin/python

from cx_Freeze import setup, Executable

setup(
    name = 'Example',
    version = '0.1',
    description='hi',
    executables = [Executable('/home/antonio/Python 26 save/opt/example.py')]
    )

if i run the resulting executable, (through the terminal) i get this error:

Fatal Python error: (pygame parachute) Segmentation Fault
Aborted

what should i do? I've searched but I found very few examples and I didn't see this error on google results

ps of course the program was running perfectly before using cx freeze


Solution

  • I have been getting a similar problem using python 2.7. I've found two causes of this segmentation fault in my own program, but I only have a solution to one of them.

    Cause 1. Initialising fonts with no path, ie calling:

    pygame.font.Font(None, font_size)
    

    In this case, valgrind reports an invalid read at the address 0x0 in ??? in pygame.font.so

    I would guess that this is because None is converted to a NULL pointer which something then assumes is a valid const char* string.

    The fix for this problem is to always supply a valid path to a font.

    Cause 2. Rendering unicode characters in fonts

    pygame.font.Font("data/DejaVuSans.ttf", 14).render(u'\u2654')
    

    valgrind reports an invalid read in PyString_AsString in libpython2.7.so.1.0

    I'm sorry to say I don't have a solution for this.

    PS: I have just found another unicode related (but not pygame related) cause of problems with cxfreeze.

    print u'\u2654'
    

    In the python interpreter will print a king (chess piece), but when the script is compiled with cxfreeze, I get the following error (not a segmentation fault):

    UnicodeEncodeError: 'ascii' codec can't encode character u'\u2654' in position 0: ordinal not in range(128)
    

    You also get this error in the python interpreter if you call:

    print str(u'\u2654')
    

    This seems to indicate that cxfreeze is assuming strings are always ascii strings.