2017-07-07 300 views
1

我已經使用Go的go-gl包了很長一段時間了。一切工作100%,直到我做了一些重構,現在我得到了似有錯誤:調用gl.GenVertexArrays時出現內存錯誤

fatal error: unexpected signal during runtime execution 
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0] 

runtime stack: 
runtime.throw(0x65d0fe, 0x2a) 
    /usr/lib/go/src/runtime/panic.go:596 +0x95 
runtime.sigpanic() 
    /usr/lib/go/src/runtime/signal_unix.go:274 +0x2db 
runtime.asmcgocall(0x8, 0x97ed40) 
    /usr/lib/go/src/runtime/asm_amd64.s:633 +0x70 

goroutine 1 [syscall, locked to thread]: 
runtime.cgocall(0x5b8ad0, 0xc420049c00, 0xc4200001a0) 
    /usr/lib/go/src/runtime/cgocall.go:131 +0xe2 fp=0xc420049bc0 sp=0xc420049b80 
github.com/go-gl/gl/v4.5-core/gl._Cfunc_glowGenVertexArrays(0x0, 0xc400000001, 0xc42006c7d8) 
    github.com/go-gl/gl/v4.5-core/gl/_obj/_cgo_gotypes.go:4805 +0x45 fp=0xc420049c00 sp=0xc420049bc0 
github.com/go-gl/gl/v4.5-core/gl.GenVertexArrays(0x1, 0xc42006c7d8) 

... 

runtime.main() 
    /usr/lib/go/src/runtime/proc.go:185 +0x20a fp=0xc420049fe0 sp=0xc420049f88 
runtime.goexit() 
    /usr/lib/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc420049fe8 sp=0xc420049fe0 

goroutine 17 [syscall, locked to thread]: 
runtime.goexit() 
    /usr/lib/go/src/runtime/asm_amd64.s:2197 +0x1 
exit status 2 

shell returned 1 

我想知道如果任何人有一個解決方案。我更新了我的驅動程序,並且空的OpenGL場景在不生成頂點數組的情況下100%工作

這裏是我的go env

GOARCH="amd64" 
GOBIN="" 
GOEXE="" 
GOHOSTARCH="amd64" 
GOHOSTOS="linux" 
GOOS="linux" 
GOPATH="/home/<user>/Projects/<project>" 
GORACE="" 
GOROOT="/usr/lib/go" 
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64" 
GCCGO="gccgo" 
CC="gcc" 
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build983667275=/tmp/go-build -gno-record-gcc-switches" 
CXX="g++" 
CGO_ENABLED="1" 
PKG_CONFIG="pkg-config" 
CGO_CFLAGS="-g -O2" 
CGO_CPPFLAGS="" 
CGO_CXXFLAGS="-g -O2" 
CGO_FFLAGS="-g -O2" 
CGO_LDFLAGS="-g -O2" 

進行調用的函數:

var vertexArrayID uint32 

// ERROR ON LINE BELOW. 
gl.GenVertexArrays(1, &vertexArrayID) 

gl.BindVertexArray(vertexArrayID) 

// Vertex buffer 
var vertexBuffer uint32 
gl.GenBuffers(1, &vertexBuffer) 
gl.BindBuffer(gl.ARRAY_BUFFER, vertexBuffer) 
gl.BufferData(gl.ARRAY_BUFFER, len(verticies)*4, gl.Ptr(verticies), gl.STATIC_DRAW) 

謝謝

+1

沒有看到你的代碼,這是一個猜測:你試圖要求一個VertexArray的標識符將被存儲在一個空的var中。 – Ripi2

+0

@ Ripi2我用導致錯誤的代碼更新了我的問題。希望它能提供更多關於這個問題的背景。 –

回答

1

打開了一個OpenGL上下文是以前的函數調用,而不是之後創建的。非常奇怪的是,空的場景仍然有效,只有在嘗試生成緩衝區後纔會崩潰。