go-gl / gl

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

Error while calling functions from all-core #104

Open olsdavis opened 6 years ago

olsdavis commented 6 years ago

Hi there!

Thanks for this library, it's very cool, but I am currently having a really annoying issue, which actually makes my program crash every time I call a function from the all-core/gl package. Here is the error:

Exception 0xc0000005 0x8 0x0 0x0
PC=0x0
signal arrived during external code execution

github.com/go-gl/gl/all-core/gl._Cfunc_glowBegin(0x0, 0x7ffe00000007)
    github.com/go-gl/gl/all-core/gl/_obj/_cgo_gotypes.go:3558 +0x4c
github.com/go-gl/gl/all-core/gl.Begin(0x7)
    A:/Apps/Go/bin/src/github.com/go-gl/gl/all-core/gl/package.go:10712 +0x3c
github.com/olsdavis/voxel/rendering.render()
    A:/Apps/Go/bin/src/github.com/olsdavis/voxel/rendering/display.go:57 +0x34
github.com/olsdavis/voxel/rendering.RenderDisplay()
    A:/Apps/Go/bin/src/github.com/olsdavis/voxel/rendering/display.go:43 +0x2e
main.main()
    A:/Apps/Go/bin/src/github.com/olsdavis/voxel/main.go:22 +0x1ec

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    A:/Apps/Go/src/runtime/asm_amd64.s:2197 +0x1
rax     0xc042031d80
rbx     0xc042031d80
rcx     0x7
rdi     0xc042031d80
rsi     0x601980
rbp     0xc042031d30
rsp     0xb1fd68
r8      0xc04201e000
r9      0x0
r10     0x0
r11     0x1
r12     0xc042038108
r13     0x0
r14     0xc0420380c0
r15     0x0
rip     0x0
rflags  0x10212
cs      0x33
fs      0x53
gs      0x2b

Process finished with exit code 2

Here is a snippet of the code which runs the LoadIdentity and makes the whole thing crash:

func (camera *Camera) InitProjection() {
    gl.Enable(gl2.PROJECTION)
    gl2.LoadIdentity() // the crash
    camera.perspective()
    gl.Enable(gl2.MODELVIEW)
}

Note: gl2 is the name of the all-core import. Yeah, not a very good clue, I could send some more code if you ask. And I guess that this does to every other function of the package, because I've tested it with some others.

Thank you in advance!

dmitshur commented 5 years ago

Are you importing more than one gl package? I'm not sure how well supported that is, if at all. Are you calling Init function for each?

Sorry, I don't have many more ideas about this.

pwaller commented 5 years ago

Hi, thanks for reaching out. Sorry for the unresponsiveness.

I'm closing this thread due to inactivity, and because there isn't obviously enough information here to try and reproduce the issue. If you still have an issue you can reproduce, please ping the thread to reopen or file a new issue, thanks!

HakShak commented 5 years ago

Just as a note, I could repro this by calling all-core/gl functions without an explicit all-core/gl.Init(). Found it by mistake when trying to use https://github.com/nullboundary/glfont at the same time as v3.3-core/gl

pwaller commented 5 years ago

Reopening to ponder if we can put protection in to prevent importing multiple gl versions in a more obvious way. Contributions welcome, I'm not working on it.

Shakeskeyboarde commented 4 years ago

@pwaller As a solution, could we use an init() function and a global in each version's gl package to detect when more than one are imported?

dertseha commented 3 years ago

I'm not sure whether there is an issue that can or should be solved (and to which degree the thread was hijacked). To reiterate:

gl packages themselves don't know about each other. It would be tricky to teach glow to add some cross-communication layer, especially if glow creates only one one API at a time. Also, I believe it is acceptable to use different APIs within the same process, such as via different libraries of a larger application. (e.g., a library provides a nice rendering of a color wheel and only wants a compatible context active when called).

In short, I see this as a case-specific problem if packages are mixed up.