google-code-export / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

pypng tracebacks when trying to save (bytes vs str problem) #717

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
pyglet checkout of r023af610e2eb installed to python 3.3.1 by
    cd working_copy
    py -3.3 setup.py install

Bugdemo script, noisy_snapshot_pypng.py , a modification of pyglet's noisy.py

It is simplified by dropping labels, key event handlers and sound.
It goes fullscreen and tries to save a screenshot.

When forcing to use the pypng codepath, like suggested in comment 2 of issue 
#707, it repeatably tracebacks:

Traceback (most recent call last):
  File "noisy_snapshot.py", line 108, in <module>
    pyglet.app.run()
  File "C:\Python33\lib\site-packages\pyglet\app\__init__.py", line 143, in run
    event_loop.run()
  File "C:\Python33\lib\site-packages\pyglet\app\base.py", line 136, in run
    self._run_estimated()
  File "C:\Python33\lib\site-packages\pyglet\app\base.py", line 165, in _run_est
imated
    timeout = self.idle()
  File "C:\Python33\lib\site-packages\pyglet\app\base.py", line 274, in idle
    redraw_all = self.clock.call_scheduled_functions(dt)
  File "C:\Python33\lib\site-packages\pyglet\clock.py", line 309, in call_schedu
led_functions
    item.func(ts - item.last_ts, *item.args, **item.kwargs)
  File "noisy_snapshot.py", line 87, in take_snapshot_fallback
    pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot.png',
encoder=PNGImageEncoder())
  File "C:\Python33\lib\site-packages\pyglet\image\__init__.py", line 456, in sa
ve
    encoder.encode(self, file, filename)
  File "C:\Python33\lib\site-packages\pyglet\image\codecs\png.py", line 104, in
encode
    writer.write_array(file, data)
  File "C:\Python33\lib\site-packages\pyglet\image\codecs\pypng.py", line 328, i
n write_array
    self.write(outfile, self.array_scanlines(pixels))
  File "C:\Python33\lib\site-packages\pyglet\image\codecs\pypng.py", line 316, i
n write
    self.write_chunk(outfile, 'IDAT', compressed + flushed)
TypeError: Can't convert 'bytes' object to str implicitly

Inspecting the code I found in pypng.py, at line 309

        if len(data):
            compressed = compressor.compress(data.tostring())
        else:
            compressed = ''

Replacing the '' by b'' fixes the crash.

Additional note:
After seeing issue #668: Sync pypng with upstream I took a look at
https://github.com/drj11/pypng/commits/master

ATM the issue is present in master, but theres a PR for fixing that:
https://github.com/drj11/pypng/pull/30

Original issue reported on code.google.com by ccanepacc@gmail.com on 29 Mar 2014 at 2:01

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by useboxnet on 29 Mar 2014 at 2:07

GoogleCodeExporter commented 9 years ago
Replaced set fullscreen with a specific size for better reproducibility across 
testbeds.

attached as noisy_snapshots_2.py

Original comment by ccanepacc@gmail.com on 29 Mar 2014 at 3:07

Attachments:

GoogleCodeExporter commented 9 years ago
I've backported the fix proposed in https://github.com/drj11/pypng/pull/30 ; 
although I need to tackle #668 and sync pypng with upstream.

Tested with 2.7.5 and 3.3.2.

Thanks for your help Claudio.

Original comment by useboxnet on 29 Mar 2014 at 6:06

GoogleCodeExporter commented 9 years ago
This issue was closed by revision da7a1f6dcccf.

Original comment by useboxnet on 29 Mar 2014 at 6:06