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

bad access: nil dereference GenBuffers() #150

Open
tod91 opened this issue May 18, 2022 · 3 comments
Open

bad access: nil dereference GenBuffers() #150

tod91 opened this issue May 18, 2022 · 3 comments
Labels

Comments

@tod91
Copy link

tod91 commented May 18, 2022

Hello I'm having issues generating an vertex buffer.

I have a very simple Shader struct as so

type Shader struct {
vbo uint32
}

which I try to use in a generate in a separate function as so:

func NewShader() *Shader {
sh := &Shader{vbo: 0}
gl.GenBuffers(1, &sh.vbo)
gl.BindBuffer(gl.ARRAY_BUFFER, sh.vbo)
gl.BufferData(gl.ARRAY_BUFFER, len(vertices)*4, gl.Ptr(vertices), gl.STATIC_DRAW)
return sh
}

however I get a panic bad access: nil dereference.

I initialize the OpenGL binding in a separate init() function.

Any help would be greatly appreciated.

@dmitshur
Copy link
Member

Does the gl41core-cube example program run okay for you?
If so, it has similar code, so you can try to spot what it's doing differently that allows it to work.

@markusheukelom
Copy link

@tod91 (It's more than a year ago you asked, but adding a solution in case some else has this issue.)

Check that you import the correct gl package. The gl package includes many different (generated) packages, one for each important OpenGL version (generated by Glow). It's easy for your IDE/go fmt to import the wrong, ie. for example github.com/go-gl/gl/all-core/gl when you need for example github.com/go-gl/gl/v4.1-core/gl on MacOS (other OS might require other specific GL versions). This is especially true if your OpenGL code is spread over multiple file. Check that they all use the correct imports.

@while-loop
Copy link

Check that you import the correct gl package

ughh. I had trouble loading textures and kept getting seg faults. This was my issue. Unrelated to this OP's ticket, but did save me! I'll try to remember this in the future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants