go-gl / gl

Go bindings for OpenGL (generated via glow)
MIT License
1.07k stars 74 forks source link

Unexpected signal during runtime execution #69

Closed jodelamo closed 7 years ago

jodelamo commented 7 years ago

Go version:

$ go version
go version go1.8.1 darwin/amd64

OS version (macOS):

$ sw_vers -productVersion
10.12.4

I'm getting a fatal error once I import and use functions from github.com/go-gl/gl/v2.1/gl in this fairly minimal program:

package main

import (
    "github.com/go-gl/gl/v2.1/gl"
    "github.com/go-gl/glfw/v3.2/glfw"
    "runtime"
)

const (
    windowTitle  = "Polyfill"
    windowWidth  = 640
    windowHeight = 480
    assetsPath   = "./assets"
)

func init() {
    // Make sure event handling is done on the main thread
    runtime.LockOSThread()
}

func main() {
    err := glfw.Init()

    if err != nil {
        panic(err)
    }
    defer glfw.Terminate()

    window := NewWindow(windowWidth, windowHeight, windowTitle)

    for !window.ShouldClose() {
        // Clear background
        gl.ClearColor(0, 0, 1.0, 1.0) // Removing this and the following line will...
        gl.Clear(gl.COLOR_BUFFER_BIT) // ... stop the application from crashing

        window.SwapBuffers()
        glfw.PollEvents()
    }
}

The error being the following:

|| fatal error: unexpected signal during runtime execution
||  /usr/local/opt/go/libexec/src/runtime/panic.go:596 +0x95
||  /usr/local/opt/go/libexec/src/runtime/signal_unix.go:274 +0x2db
||  /usr/local/opt/go/libexec/src/runtime/asm_amd64.s:633 +0x70
||  /usr/local/opt/go/libexec/src/runtime/proc.go:2681 +0x41
||  /usr/local/opt/go/libexec/src/runtime/cgocall.go:131 +0xe2 fp=0xc42005ded8 sp=0xc42005de98
||  github.com/go-gl/gl/v2.1/gl/_obj/_cgo_gotypes.go:7758 +0x45 fp=0xc42005df20 sp=0xc42005ded8
||  /Users/jorum/Dev/go/src/github.com/go-gl/gl/v2.1/gl/package.go:18348 +
||  /Users/jorum/Dev/go/src/github.com/jlowgren/polyfill/polyfill.go:33 +0xc6 fp=0xc42005df88 sp=0xc42005df48
||  /usr/local/opt/go/libexec/src/runtime/proc.go:185 +0x20a fp=0xc42005dfe0 sp=0xc42005df88
||  /usr/local/opt/go/libexec/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc42005dfe8 sp=0xc42005dfe0
||  /usr/local/opt/go/libexec/src/runtime/asm_amd64.s:
dmitshur commented 7 years ago

this fairly minimal program

Did you find that minimal program somewhere within our resources?

I believe you're missing important calls to window.MakeContextCurrent and gl.Init. You can't call any gl functions until you do gl.Init successfully:

https://godoc.org/github.com/go-gl/gl/v2.1/gl#Init

Try the example at https://github.com/go-gl/examples/tree/master/gl21-cube, does it work?

jodelamo commented 7 years ago

You're so right. I was mixing up gl.Init with glfw.Init. Thank you!