[SOLVED] GL30.glGenVertexArrays() crash

Started by overlisted, September 12, 2019, 14:19:57

Previous topic - Next topic

overlisted

When I try to run code with GL30.glGenVertexArrays() the OpenGL natives crash.








P.S. I'm new to LWJGL and Java.

KaiHH

Doing OpenGL calls inside of a constructor and on top of that initializing an instance field directly at declaration is not a good idea. In your case, the GL call and the constructor is called in a static initializer block:
j  org.lwjgl.opengl.GL30.nglGenVertexArrays(IJ)V+0
j  org.lwjgl.opengl.GL30.glGenVertexArrays()I+20
j  net.matorassan.simplegfx.VertexArray.<init>(I[F)V+5
j  net.matorassan.cubes.DrawThread.<init>()V+407
j  net.matorassan.cubes.Cubes.<clinit>()V+14 <---------- static initializer block in class "Cubes"

The static initializer block may possibly be a static field being initialized at declaration with a new instance of DrawThread.

Chances are that the OpenGL context has not been initialized then.
You may also want to run the JVM with: https://github.com/LWJGLX/debug#how

overlisted

Quote from: KaiHH on September 12, 2019, 14:23:48
Doing OpenGL calls inside of a constructor and on top of that initializing an instance field directly at declaration is not a good idea. In your case, the GL call and the constructor is called in a static initializer block:
j  org.lwjgl.opengl.GL30.nglGenVertexArrays(IJ)V+0
j  org.lwjgl.opengl.GL30.glGenVertexArrays()I+20
j  net.matorassan.simplegfx.VertexArray.<init>(I[F)V+5
j  net.matorassan.cubes.DrawThread.<init>()V+407
j  net.matorassan.cubes.Cubes.<clinit>()V+14 <---------- static initializer block in class "Cubes"

The static initializer block may possibly be a static field being initialized at declaration with a new instance of DrawThread.

Chances are that the OpenGL context has not been initialized then.
You may also want to run the JVM with: https://github.com/LWJGLX/debug#how

Oh thank you! I forgot about these lines: