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

SIGSEGV even with runtime.LockOSThread() with gl.CreateShader #120

Closed
qhdwight opened this issue Oct 25, 2019 · 3 comments
Closed

SIGSEGV even with runtime.LockOSThread() with gl.CreateShader #120

qhdwight opened this issue Oct 25, 2019 · 3 comments

Comments

@qhdwight
Copy link

qhdwight commented Oct 25, 2019

go.mod:

module github.com/qhdwight/biomequest

go 1.13.3

require (
	github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
	github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1
	github.com/go-gl/mathgl v0.0.0-20190713194549-592312d8590a
)

I am first initializing GLFW, setting window hints to use core profile forward compatible with 4.1, making content current, then calling gl.Init(). That all works fine with no panicking. However, as soon as I call gl.CreateShader with the gl.VERTEX_SHADER (0x8B31) code I get a segmentation violation.

I will also note that this same program works fine on my Windows machine.
It does not work if I use OpenGL 4.1, but works if I use 4.6 (which is not available on macOS)

I am on macOS Catalina 10.15.

GOROOT=/usr/local/Cellar/go/1.13.3/libexec #gosetup
GOPATH=/Users/qhdwight/go #gosetup
/usr/local/Cellar/go/1.13.3/libexec/bin/go build -o /private/var/folders/5r/457_n8gj3dldmp9cl8_ygsr00000gn/T/___Play github.com/qhdwight/biomequest #gosetup
# github.com/go-gl/glfw/v3.2/glfw
In file included from ../../go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/c_glfw_darwin.go:8:
../../go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/glfw/src/cocoa_window.m:989:9: warning: multiple methods named 'center' found [-Wobjc-multiple-method-names]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSCollectionViewCompositionalLayout.h:601:19: note: using
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:312:1: note: also found
/private/var/folders/5r/457_n8gj3dldmp9cl8_ygsr00000gn/T/___Play #gosetup
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]

runtime stack:
runtime.throw(0x416d39d, 0x2a)
        /usr/local/Cellar/go/1.13.3/libexec/src/runtime/panic.go:774 +0x72
runtime.sigpanic()
        /usr/local/Cellar/go/1.13.3/libexec/src/runtime/signal_unix.go:378 +0x47c

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x40ecbb0, 0xc0000b1718, 0x0)
        /usr/local/Cellar/go/1.13.3/libexec/src/runtime/cgocall.go:128 +0x5b fp=0xc0000b16e8 sp=0xc0000b16b0 pc=0x4004aeb
github.com/go-gl/gl/v4.6-core/gl._Cfunc_glowCreateShader(0x0, 0x8b31, 0x0)
        _cgo_gotypes.go:5458 +0x4d fp=0xc0000b1718 sp=0xc0000b16e8 pc=0x40cbe5d
github.com/go-gl/gl/v4.6-core/gl.CreateShader(...)
        /Users/qhdwight/go/pkg/mod/github.com/go-gl/[email protected]/v4.6-core/gl/package.go:9138
github.com/qhdwight/biomequest/graphics.compileShader(0xc0000cc000, 0x159, 0x8b31, 0x359, 0xc0000cc000, 0x159)
        /Users/qhdwight/Projects/biomequest/graphics/shader.go:91 +0x4a fp=0xc0000b17f8 sp=0xc0000b1718 pc=0x40cf4ba
github.com/qhdwight/biomequest/graphics.CompileShaderFromPath(0x4160dc4, 0x8, 0x8b31, 0x4433120, 0xc0000b1888, 0x40b3698)
        /Users/qhdwight/Projects/biomequest/graphics/shader.go:53 +0xe6 fp=0xc0000b1840 sp=0xc0000b17f8 pc=0x40ceed6
github.com/qhdwight/biomequest/game.newShader(0x4160dc4, 0x8, 0x8b31, 0x0, 0x0, 0x0)
        /Users/qhdwight/Projects/biomequest/game/game.go:252 +0x41 fp=0xc0000b1898 sp=0xc0000b1840 pc=0x40d1641
github.com/qhdwight/biomequest/game.Start()
        /Users/qhdwight/Projects/biomequest/game/game.go:125 +0xe6 fp=0xc0000b7f50 sp=0xc0000b1898 pc=0x40d0276
main.main()
        /Users/qhdwight/Projects/biomequest/main.go:13 +0x20 fp=0xc0000b7f60 sp=0xc0000b7f50 pc=0x40d1ce0
runtime.main()
        /usr/local/Cellar/go/1.13.3/libexec/src/runtime/proc.go:203 +0x21e fp=0xc0000b7fe0 sp=0xc0000b7f60 pc=0x402d71e
runtime.goexit()
        /usr/local/Cellar/go/1.13.3/libexec/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc0000b7fe8 sp=0xc0000b7fe0 pc=0x4055d71

Process finished with exit code 2

My code is in a few different places but I have:

	if err := initGlfw(); err != nil {
		panic(err)
	}
	window, err := initWindow()
	if err != nil {
		panic(err)
	}
	if err := gl.Init(); err != nil {
		panic(err)
	}
	vertShader, err := newShader(vertPath, gl.VERTEX_SHADER)
	if err != nil {
		panic(err)
	}
func initGlfw() error {
	if err := glfw.Init(); err != nil {
		return err
	}
	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	return nil
}
func initWindow() (*glfw.Window, error) {
	window, err := glfw.CreateWindow(width, height, "Biomequest", nil, nil)
	if err != nil {
		return nil, err
	}
	window.MakeContextCurrent()
	window.SetInputMode(glfw.StickyKeysMode, gl.TRUE)
	window.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
	glfw.SwapInterval(0)
	return window, nil
}
func compileShader(src string, shaderType uint32) (*Shader, error) {
	handle := gl.CreateShader(shaderType) // <-------- WHERE IT CRASHES
	csrc, csrcFree := gl.Strs(src + "\x00")
	gl.ShaderSource(handle, 1, csrc, nil)
	csrcFree()
	gl.CompileShader(handle)
	var status int32
	gl.GetShaderiv(handle, gl.COMPILE_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetShaderiv(handle, gl.INFO_LOG_LENGTH, &logLength)
		log := strings.Repeat("\x00", int(logLength+1))
		gl.GetShaderInfoLog(handle, logLength, nil, gl.Str(log))
		return nil, fmt.Errorf("failed to compile:\n%v\n%v", src, log)
	}
	return &Shader{Handle: handle}, nil
}
@qhdwight
Copy link
Author

In a different go file I was accidentally importing the wrong version (v4.6 instead of v4.1). This is why you see that in the error logs.

@dmitshur
Copy link
Member

Hmm, I wonder if there’s anything in common here with golang/go#35177.

@oyagci
Copy link

oyagci commented Mar 8, 2022

Thank you. I had the same problem.

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