los-cocos / cocos

graphic library for games and multimedia, for python language on PC-like hardware
http://los-cocos.github.io/cocos-site/
Other
633 stars 147 forks source link

Crash when updating opacity of ColorLayer in python3 #330

Closed MartinHowarth closed 4 years ago

MartinHowarth commented 4 years ago

This code is the problem at https://github.com/los-cocos/cocos/blob/master/cocos/layer/util_layers.py#L142

    def _set_color(self, rgb):
        self._rgb = map(int, rgb)
        self._update_color()

Basically, map in python3 is a generator rather than resulting in a tuple - so it can only be used once. Therefore if you update opacity twice in a row, or immediately after setting the colour, it crashes with the error ValueError: not enough values to unpack (expected 3, got 0)

Minimal repro:

            color_layer.color = (100, 100, 100)
            color_layer.opacity = 100

Fix should be to just replace self._rgb = map(int, rgb) with self._rgb = tuple(map(int, rgb))

Seen using python 3.8 on windows 10

ccanepa commented 4 years ago

Thanks for the report and patch.

Commited to master https://github.com/los-cocos/cocos/commit/4d2f37a2496f0a6aaf4f81e71757c0c2bc1d68e7

Will be released in a few days.