Hello Guest

[SOLVED] GL30.glGenVertexArrays() crash

  • 2 Replies
  • 5077 Views
*

Offline overlisted

  • *
  • 15
  • #MakeMinecraftOpenSource
[SOLVED] GL30.glGenVertexArrays() crash
« on: September 12, 2019, 14:19:57 »
When I try to run code with GL30.glGenVertexArrays() the OpenGL natives crash.








P.S. I'm new to LWJGL and Java.
« Last Edit: September 12, 2019, 15:45:35 by True_han »

*

Offline KaiHH

  • ****
  • 334
Re: GL30.glGenVertexArrays() crash
« Reply #1 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
« Last Edit: September 12, 2019, 14:26:20 by KaiHH »

*

Offline overlisted

  • *
  • 15
  • #MakeMinecraftOpenSource
Re: GL30.glGenVertexArrays() crash
« Reply #2 on: September 12, 2019, 14:41:49 »
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: