1. pygame
  2. pygame
  3. pygame

Issues

Issue #184 resolved

pygame osx implementation Video_AutoInit fails with NotImplementedError

douglasl
created an issue

see: https://bitbucket.org/pygame/pygame/src/90f8019b31d294fc9264c0f3da66ceeb0e0fd154/lib/macosx.py?at=default

and: https://bitbucket.org/pygame/pygame/src/90f8019b31d294fc9264c0f3da66ceeb0e0fd154/lib/pkgdata.py?at=default

macosx.py only caters for IOError, in this code:

        try:
            default_icon_data = getResource('pygame_icon.tiff').read()
        except IOError:
            default_icon_data = None

Where as pkgdata.py can raise NotImplementedError in some cases:

try:
    from pkg_resources import resource_stream, resource_exists
except ImportError:
    def resource_exists(package_or_requirement, resource_name):
        return False
    def resource_stream(package_of_requirement, resource_name):
        raise NotImplementedError

Specifically with pyinstaller this results in errors like: ERROR: pygame.macosx.Video_AutoInit() call FAILED

Worse, since the python extension doesn't bother to catch the raised exception, the stacktrace is lost, making it virtually impossible to debug.

Anyway, macosx.py should be patched to correctly support the possible type of errors that may be raised in the code above.

Comments (9)

  1. René Dudfield

    Thanks for the report :)

    Are you suggesting this?

            try:
                default_icon_data = getResource('pygame_icon.tiff').read()
            except IOError:
                default_icon_data = None
            except NotImplementedError:
                default_icon_data = None
    

    It seems pyinstaller will then not get any of the resources? I think it's better to fix the import perhaps, or maybe add a log in there so we can see the exception of why it is not getting imported.

  2. douglasl reporter

    Yes.

    It's worth noting that letting the exception 'bubble up' to see what the problem actually was doesn't work because this function is called here:

    https://bitbucket.org/pygame/pygame/src/90f8019b31d294fc9264c0f3da66ceeb0e0fd154/src/base.c?at=default#cl-566

    Which throws away any error messages.

    Maybe logging the exception is the way to go?

    Either way, it should not hard stop pygame just because the resources thing didn't work; lots of systems (eg, specifically, kivy) use their own resource loading, and don't care about the pygame resource system.

  3. Winston W

    Tito posted a workaround here:

    https://github.com/kivy/kivy/issues/1638
    

    To get ride of the issue, just add at the end of kivy/tools/packaging/pyinstaller_hooks/rt-hook-kivy.py:

    Monkey-patch pygame to get around an issue with Pygame window icon and

    PyInstaller 2.1. See kivy issue #1638

    import pygame.pkgdata _original_getResource = pygame.pkgdata.getResource def getResource(identifier, args, *kwargs):

    if identifier == 'pygame_icon.tiff':

    raise IOError()

    return _original_getResource(identifier, args, *kwargs) pygame.pkgdata.getResource = getResource

    Winston Wolff Stratolab - Games for Learning tel: (917) 543 8852 web: www.stratolab.com

    Play Electro•pocalypse -- our new game about electricity -- http://stratolab.com/electropocalypse/

  4. Log in to comment