Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: simple program crashes #3

Closed
kinghajj opened this issue Apr 2, 2012 · 8 comments
Closed

Windows: simple program crashes #3

kinghajj opened this issue Apr 2, 2012 · 8 comments

Comments

@kinghajj
Copy link

kinghajj commented Apr 2, 2012

package main

import "github.com/nsf/termbox-go"

func main() {
    // Initialize termbox
    if err := termbox.Init(); err != nil {
        panic(err)
    }
    defer termbox.Close()

    // Clear screen, set a cell, flush buffer
    termbox.Clear(termbox.ColorDefault, termbox.ColorGreen)
    termbox.SetCell(1, 1, '#', termbox.ColorRed, termbox.ColorDefault)
    termbox.Flush()

    // Wait for events and respond appropriately
loop:
    for {
        switch ev := termbox.PollEvent(); ev.Type {
        case termbox.EventKey:
            switch ev.Key {
            case termbox.KeyEsc:
                break loop
            }
        }
    }
}

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x1 addr=0x0 pc=0x76fe12da]

goroutine 1 [syscall]:
syscall.Syscall6(0x76ff4930, 0x5, 0x7, 0xf84008f000, 0x5dc0, ...)
C:/.../go/src/pkg/runtime/zsyscall_windows_amd64.c:97 +0x55
github.com/nsf/termbox-go.write_console_output_attribute(0x7, 0xf84008f000, 0x5dc000005dc0, 0x0, 0x0, ...)
C:/go/src/pkg/github.com/nsf/termbox-go/termbox_windows.go:99 +0xd6
github.com/nsf/termbox-go.Flush()
C:/go/src/pkg/github.com/nsf/termbox-go/api_windows.go:67 +0xc1
main.main()
C:/.../playground.go:15 +0xc1

goroutine 2 [syscall]:
created by runtime.main
C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist119677522/go/src/pkg/runtime/proc.c:221

goroutine 3 [syscall]:
syscall.Syscall6(0x76ff4fd0, 0x4, 0x3, 0xf840015a20, 0x1, ...)
C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist119677522/go/src/pkg/runtime/zsyscall_windows_amd64.c:97 +0x55
github.com/nsf/termbox-go.read_console_input(0x3, 0xf840015a20, 0x0, 0x0, 0x0, .
..)
C:/go/src/pkg/github.com/nsf/termbox-go/termbox_windows.go:138 +0x90
github.com/nsf/termbox-go.input_event_producer()
C:/go/src/pkg/github.com/nsf/termbox-go/termbox_windows.go:560 +0x5e
created by github.com/nsf/termbox-go.Init
C:/go/src/pkg/github.com/nsf/termbox-go/api_windows.go:51 +0x361

@nsf
Copy link
Owner

nsf commented Apr 2, 2012

Seems like x86_64 vs. x86 issue. I use the same structures on both platforms, perhaps it was a bad decission. Can't really do much here, because I have no x86_64 windows installation, but will take a closer look on things that may cause a problem.

@nsf
Copy link
Owner

nsf commented Apr 5, 2012

So, I tried the example on my windows machine (x86), it works... Definitely something architecture specific. Can't see it. Will keep looking for an amd64 windows machine.

@dmdavis10
Copy link

I am getting the same result, and I am not running a 64bit OS. My machine is 64bit, but I am running 32bit Windows 7, and 32 bit Go. I just installed Go and termbox, and got this error when running any of the demos. I then created my own basic program, almost exactly like the one in the original bug report, and I got the same error. The error does not occur when I remove termbox.Flush().

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x1 addr=0x0 pc=0x7616d68d]

goroutine 1 [syscall]:
syscall.Syscall6(0x7616d705, 0x5, 0x13, 0x11c21000, 0x1, ...)
C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist579160455/go/src/pkg/runtime/zsyscall_windows_386.c:97 +0x49
github.com/nsf/termbox-go.write_console_output_attribute(0x13, 0x11c21000, 0x1, 0x57e40, 0x10001, ...)
C:/Go/src/pkg/github.com/nsf/termbox-go/termbox_windows.go:99 +0x9f
github.com/nsf/termbox-go.Flush(0x1, 0x1)
C:/Go/src/pkg/github.com/nsf/termbox-go/api_windows.go:67 +0xaa
main.main()
C:/Go/src/term/term.go:16 +0xe1

goroutine 2 [syscall]:
created by runtime.main
C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist579160455/go/src/pkg/runtime/proc.c:221

goroutine 3 [syscall]:
syscall.Syscall6(0x7616d082, 0x4, 0xf, 0x11685a60, 0x1, ...)
C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist579160455/go/src/pkg/runtime/zsyscall_windows_386.c:97 +0x49
github.com/nsf/termbox-go.read_console_input(0xf, 0x11685a60, 0x0, 0x0)
C:/Go/src/pkg/github.com/nsf/termbox-go/termbox_windows.go:138 +0x78
github.com/nsf/termbox-go.input_event_producer()
C:/Go/src/pkg/github.com/nsf/termbox-go/termbox_windows.go:574 +0x52
created by github.com/nsf/termbox-go.Init
C:/Go/src/pkg/github.com/nsf/termbox-go/api_windows.go:51 +0x2f0
exit status 2

@nsf
Copy link
Owner

nsf commented Sep 1, 2012

Well, I was testing it on windows xp 32 bit. Now I actually have the Windows 7 64 bit. Will check that out soon.

@nsf nsf closed this as completed Sep 1, 2012
@nsf nsf reopened this Sep 1, 2012
@dmdavis10
Copy link

I just installed cygwin on my machine, and I no longer get that error. Don't know if that was coincidence or not.

@dmdavis10
Copy link

I take that back, kind of. My simple little program runs without error now, though nothing is visible from my call to SetCell. It does wait on events, fmt.Println prints to the screen, and it quits correctly on a key press. However, I still get the same error when I try to run any of your demo programs.

@nsf
Copy link
Owner

nsf commented Sep 1, 2012

You need to call termbox.Flush(), that submits everything to the console. And I think you'll have your segfault if you do that.

@nsf nsf closed this as completed in e2d7b34 Sep 30, 2012
@nsf
Copy link
Owner

nsf commented Sep 30, 2012

It clearly works now on my w7-x64. Screenshot proof (godit.exe is a 64 bit process for sure):
http://ompldr.org/vZnAydg/godit-w64.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants