JoelOtter / termloop

Terminal-based game engine for Go, built on top of Termbox
Other
1.42k stars 83 forks source link

Example throwing error : Image.go #24

Closed iMaxopoly closed 8 years ago

iMaxopoly commented 8 years ago
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/nsf/termbox-go.cell_to_char_info(0x59000000000000, 0x0)
        C:/Users/#/Documents/GoProjects/src/github.com/nsf/termbox-go/termbox_windows.go:526 +0x18b
github.com/nsf/termbox-go.append_diff_line(0xe, 0x78)
        C:/Users/#/Documents/GoProjects/src/github.com/nsf/termbox-go/termbox_windows.go:466 +0xe0
github.com/nsf/termbox-go.prepare_diff_messages()
        C:/Users/#/Documents/GoProjects/src/github.com/nsf/termbox-go/termbox_windows.go:510 +0x265
github.com/nsf/termbox-go.Flush(0x0, 0x0)
        C:/Users/#/Documents/GoProjects/src/github.com/nsf/termbox-go/api_windows.go:109 +0x42
github.com/JoelOtter/termloop.(*Screen).Draw(0xc082010090)
        C:/Users/#/Documents/GoProjects/src/github.com/JoelOtter/termloop/screen.go:65 +0x32f
github.com/JoelOtter/termloop.(*Game).Start(0xc08204e4b0)
        C:/Users/#/Documents/GoProjects/src/github.com/JoelOtter/termloop/game.go:115 +0x51f
main.main()
        C:/Users/#/Documents/GoProjects/src/Delilah/main.go:54 +0x220

goroutine 13 [chan send]:
github.com/JoelOtter/termloop.poll(0xc082006740)
        C:/Users/#/Documents/GoProjects/src/github.com/JoelOtter/termloop/input.go:33 +0x9a
created by github.com/JoelOtter/termloop.(*input).start
        C:/Users/#/Documents/GoProjects/src/github.com/JoelOtter/termloop/input.go:19 +0x3c

Above Error encountered when running the image.go example. Used random png, jpeg files. Nothing worked. Thank you :)

JoelOtter commented 8 years ago

Hi Manish,

Can you share your system configuration - Go version, operating system, terminal?

Cheers

JoelOtter commented 8 years ago

Hi @kryptodev, did you solve your problem?

iMaxopoly commented 8 years ago
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/nsf/termbox-go.cell_to_char_info(0x8a000000000000, 0x0)
        C:/Users/#/Documents/GoProjects/src/github.com/nsf/termbox-go/termbox_windows.go:526 +0x18b
github.com/nsf/termbox-go.append_diff_line(0x1b, 0x78)
        C:/Users/#/Documents/GoProjects/src/github.com/nsf/termbox-go/termbox_windows.go:466 +0xe0
github.com/nsf/termbox-go.prepare_diff_messages()
        C:/Users/#/Documents/GoProjects/src/github.com/nsf/termbox-go/termbox_windows.go:510 +0x265
github.com/nsf/termbox-go.Flush(0x0, 0x0)
        C:/Users/#/Documents/GoProjects/src/github.com/nsf/termbox-go/api_windows.go:109 +0x42
github.com/JoelOtter/termloop.(*Screen).Draw(0xc08200e090)
        C:/Users/#/Documents/GoProjects/src/github.com/JoelOtter/termloop/screen.go:65 +0x32f
github.com/JoelOtter/termloop.(*Game).Start(0xc082048630)
        C:/Users/#/Documents/GoProjects/src/github.com/JoelOtter/termloop/game.go:115 +0x520
main.main()
        C:/Users/#/Documents/GoProjects/src/practice/main.go:54 +0x220

Hi, my apologies for replying late, almost forgot about this..

Operating system Windows 64 bit. Golang Version at the time of creating this issue was 1.5.2. Recompiled just now and received aforementioned error with golang version 1.6.2 beta. Console used was Windows Command prompt. Seems like nothing changed.

Used your image.go source code to compile, and passed this image(after saving to disk of course) as argument http://freepngimages.com/wp-content/uploads/2014/05/obama4_1.png

Thank you

JoelOtter commented 8 years ago

Thanks. I've tried the example with your image on both iTerm2 and Terminal.app, and had no issues. I wonder if this is some issue with Windows Command Prompt I'd not encountered before - my intuition is that it may not correctly report terminal width, so Termbox is trying to draw to a terminal cell that doesn't exist. Unfortunately I don't have access to a Windows machine so I can't really test this theory myself.

To help us out, it would be great if you could:

iMaxopoly commented 8 years ago

Just tried it on another windows(x64) machine and the same error is observable with different images.

Also tried it on Cmder console and it produces the same error. Also tried a very small image (48 x 48), and it still showed the same error.

JoelOtter commented 8 years ago

OK, looks like the issue here is actually with the colours - Termbox is trying to consult a colour lookup table, but the colour in the image is out-of-bounds in the table. This is because your console doesn't support 256 colours. Normally Termbox would just switch colour mode, but it would appear the terminal you're using isn't reporting its 256 support correctly.

It works fine in Terminal.app, which is kind of weird given it doesn't support 256 colours either - it just looks bad, instead of crashing outright. This is because Terminal.app isn't using the Windows-exclusive code. I may be able to fix this with a pull request to Termbox. In the meantime, I suggest you avoid using colours beyond the range [0, 8]. There may also be applications out there for Windows which emulate a Linux terminal.

How do the other examples provided work for you? Do any of them crash with a similar error message?

JoelOtter commented 8 years ago

OK, @kryptodev - can you try using the branch termloop/windows? It uses my fork of Termbox, which has a fix which should help your issue.

In the Termloop directory, do:

git fetch origin
git checkout windows

You may need to run the following to get it to work:

go get github.com/JoelOtter/termbox-go

Let me know if this helps - if it does, I can submit this as a patch to termbox-go.

iMaxopoly commented 8 years ago

Works as expected :+1: :smiley:

I'll recommend you test on windows personally before patching it onto main branch regardless.

Thanks.

JoelOtter commented 8 years ago

I've filed a pull request on termbox-go.