调用gl.GenVertexArrays时出现内存错误。

huangapple go评论152阅读模式
英文:

Memory error when calling gl.GenVertexArrays

问题

我已经使用Go的go-gl包有一段时间了。一切都正常工作,直到我进行了一些重构,现在我遇到了一个奇怪的错误:

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场景可以正常工作,而不会生成顶点数组。

这是我的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)

谢谢。

英文:

I've been using Go's go-gl package for quite a while now. Everything was working 100% until I did some refactoring and now I'm getting the stranges error:

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

I was wondering if anyone has a solution. I've updated my drivers and a empty OpenGL scene works 100% without generating vertex arrays.

Here is my go env

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

The function making the call:

var vertexArrayID uint32

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

gl.BindVertexArray(vertexArrayID)

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

Thank you

答案1

得分: 1

原来是在函数调用之后创建了一个OpenGL上下文,而不是在之前。非常奇怪的是,空场景仍然可以工作,只有在尝试生成缓冲区之后才崩溃。

英文:

Turns out the a OpenGL context was created after the function call instead of before. Very strange that the empty scene still worked and only crashed after trying to generate buffers.

huangapple
  • 本文由 发表于 2017年7月8日 00:07:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/44975330.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定