jamis / theseus

A very flexible random maze generator, solver, and renderer for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error trying to save PNGs

Tcepsa opened this issue · comments

Description:
ChunkyPNG throws an error when trying to save a maze as a PNG file.

Steps to reproduce
$ gem install theseus #Installs theseus v 1.0.2 and ChunkyPNG 0.12.0
$ theseus -w 10 -o maze -f png #Generates the following stacktrace
/home/tcepsa/.gem/ruby/2.3.0/gems/chunky_png-0.12.0/lib/chunky_png/canvas/png_encoding.rb:330:in encode_png_pixels_to_scanline_method': No encoder found for color mode 4 and 8-bit depth! (ChunkyPNG::NotSupported) from /home/tcepsa/.gem/ruby/2.3.0/gems/chunky_png-0.12.0/lib/chunky_png/canvas/png_encoding.rb:213:inencode_png_image_pass_to_stream'
from /home/tcepsa/.gem/ruby/2.3.0/gems/chunky_png-0.12.0/lib/chunky_png/canvas/png_encoding.rb:177:in encode_png_image_without_interlacing' from /home/tcepsa/.gem/ruby/2.3.0/gems/chunky_png-0.12.0/lib/chunky_png/canvas/png_encoding.rb:164:inencode_png_pixelstream'
from /home/tcepsa/.gem/ruby/2.3.0/gems/chunky_png-0.12.0/lib/chunky_png/canvas/png_encoding.rb:83:in to_datastream' from /home/tcepsa/.gem/ruby/2.3.0/gems/chunky_png-0.12.0/lib/chunky_png/image.rb:62:into_datastream'
from /home/tcepsa/.gem/ruby/2.3.0/gems/chunky_png-0.12.0/lib/chunky_png/canvas/png_encoding.rb:48:in to_blob' from /home/tcepsa/.gem/ruby/2.3.0/gems/theseus-1.0.2/lib/theseus/formatters/png/orthogonal.rb:36:ininitialize'
from /home/tcepsa/.gem/ruby/2.3.0/gems/theseus-1.0.2/lib/theseus/maze.rb:656:in new' from /home/tcepsa/.gem/ruby/2.3.0/gems/theseus-1.0.2/lib/theseus/maze.rb:656:into'
from /home/tcepsa/.gem/ruby/2.3.0/gems/theseus-1.0.2/bin/theseus:259:in block in <top (required)>' from /home/tcepsa/.gem/ruby/2.3.0/gems/theseus-1.0.2/bin/theseus:259:inopen'
from /home/tcepsa/.gem/ruby/2.3.0/gems/theseus-1.0.2/bin/theseus:259:in <top (required)>' from /home/tcepsa/.gem/ruby/2.3.0/bin/theseus:23:inload'
from /home/tcepsa/.gem/ruby/2.3.0/bin/theseus:23:in `

'

This has happened on Arch and Debian (RasPi) Linux. It does not happen on the Windows system that I tried it on. The Linux systems all had recent (> 2.0.0) versions of Ruby; I believe the Windows system is running something in the 1.9 range (I'll try to update this with the exact version) so I suspect it may have something to do with the version of Ruby.

I've tried modifying the to_blob call in the orthogonal png formatter to specify the color mode and bit depth to see whether that helps, but I don't know enough Ruby to actually try it after updating the .rb file. (Naive attempts to rebuild by typing "rake" at the command line in the project root have unfortunately resulted in deprecation errors in the rakefile).

If you can't/won't fix it, could you suggest a workaround?

I get the same error on Ubuntu 16.04 with ruby 2.3.0 but not on Ubuntu 14.04 with ruby 1.9.3. The problem is that the behavior of respond_to? changed in ruby 2.0 and the version of ChunkyPNG that theseus uses has not been updated to handle the change. Updating to the latest version of ChunkyPNG should fix it.

@MtnViewJohn - how do you update to the latest version of ChunkyPNG? I tried sudo gem update, and I can see two versions of chunk_png installed, but Theseus still doesn't make pngs. Do I need to edit Theseus somehow to use the later version?

I'm not skilled enough in Ruby to change the version dependence on ChunkyPNG. What I did was modify ChunkyPNG 0.12.0 to work with Ruby 2.3. Edit the file /var/lib/gems/2.3.0/gems/chunky_png-0.12.0/lib/chunky_png/canvas/png_encoding.rb at line 330 change

respond_to?(encoder_method)

to

respond_to?(encoder_method,true)

You can make a similar change at line 358 of png_decoding.rb.

Thanks! I'll give that a go.

I managed to get rbenv to work to run theseus under Ruby 1.9.2, but it seemed very involved - I kept trying stuff until it worked, so I'm not sure how much of what I did was essential. I like your way better.

Sorry this program has fallen so far behind the curve! I've updated the master branch to work with the latest ChunkyPNG (1.3.x). I don't have time just now to make a new gem, but I'll work on that.

Okay, version 1.1.0 has been released as a gem. It works with the latest version of ChunkyPNG. You should be able to "gem install theseus" and have it just work with modern Rubies.