pygame osx implementation Video_AutoInit fails with NotImplementedError

Issue #184 resolved
Doug created an issue


and: only caters for IOError, in this code:

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

Where as can raise NotImplementedError in some cases:

    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, should be patched to correctly support the possible type of errors that may be raised in the code above.

Comments (11)

  1. René Dudfield

    Thanks for the report :)

    Are you suggesting this?

                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. Doug reporter


    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:

    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 Wolff

    Tito posted a workaround here:

    To get ride of the issue, just add at the end of kivy/tools/packaging/pyinstaller_hooks/

    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:

    Play Electro•pocalypse -- our new game about electricity --

  4. Log in to comment