title: OpenGL/lwjgl texture creation sigsegv
body: <p>Im trying to create a simple OpenGL program using lwjgl and I'm currently stuck at creating a texture to render.</p>
  <p>The error I'm getting is a segmentation fault:</p>
  <pre><code>#
  # A fatal error has been detected by the Java Runtime Environment:
  #
  #  SIGSEGV (0xb) at pc=0x00007fff6c894ab6, pid=18463, tid=775
  #
  # JRE version: OpenJDK Runtime Environment (14.0.1+7) (build 14.0.1+7)
  # Java VM: OpenJDK 64-Bit Server VM (14.0.1+7, mixed mode, sharing, tiered, compressed oops, g1 gc, bsd-amd64)
  # Problematic frame:
  # C  [libGLImage.dylib+0x11ab6]  _Z15glgConvertTo_32I23GLGConverter_RGB8_ARGB8L9GLGMemory1EEvPK15GLGOperationRecPK15GLDPixelModeRec+0x59
  #
  # No core dump will be written. Core dumps have been disabled. To enable core dumping, try &quot;ulimit -c unlimited&quot; before starting Java again
  #
  # If you would like to submit a bug report, please visit:
  #   https://bugreport.java.com/bugreport/crash.jsp
  # The crash happened outside the Java Virtual Machine in native code.
  # See problematic frame for where to report the bug.
  #
  </code></pre>
  <p>Machine info:</p>
  <pre><code>Host: iMac16,2 x86_64 2800 MHz, 4 cores, 8G, Darwin 20.2.0
  Time: Wed Jun  2 23:49:46 2021 CEST elapsed time: 178 seconds (0d 0h 2m 58s)
  </code></pre>
  <p>Problematic JVM thread stack:</p>
  <pre><code>Stack: [0x00007ffee5272000,0x00007ffee5a72000],  sp=0x00007ffee5a6de10,  free space=8175k
  Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
  C  [libGLImage.dylib+0x11ab6]  _Z15glgConvertTo_32I23GLGConverter_RGB8_ARGB8L9GLGMemory1EEvPK15GLGOperationRecPK15GLDPixelModeRec+0x59
  C  [libGLImage.dylib+0x6227]  glgProcessPixelsWithProcessor+0xdf4
  C  [AppleIntelBDWGraphicsGLDriver+0x13500]  glrWriteTextureData+0x1438
  C  [GLEngine+0x189f7]  glTexImage2D_Exec+0x52b
  C  [libGL.dylib+0x3195]  glTexImage2D+0x37
  C  [liblwjgl_opengl.dylib+0xb22e]
  j  org.lwjgl.opengl.GL11C.nglTexImage2D(IIIIIIIIJ)V+0
  j  org.lwjgl.opengl.GL11C.glTexImage2D(IIIIIIIILjava/nio/ByteBuffer;)V+17
  j  org.lwjgl.opengl.GL11.glTexImage2D(IIIIIIIILjava/nio/ByteBuffer;)V+14
  j  rendering.Window.render()V+420
  j  rendering.Window.loop()V+8
  j  rendering.Window.main([Ljava/lang/String;)V+25
  v  ~StubRoutines::call_stub
  V  [libjvm.dylib+0x34bbbe]  _ZN9JavaCalls11call_helperEP9JavaValueRK12methodHandleP17JavaCallArgumentsP6Thread+0x256
  V  [libjvm.dylib+0x39032d]  _ZL17jni_invoke_staticP7JNIEnv_P9JavaValueP8_jobject11JNICallTypeP10_jmethodIDP18JNI_ArgumentPusherP6Thread+0x11c
  V  [libjvm.dylib+0x393c10]  jni_CallStaticVoidMethod+0x1b3
  C  [libjli.dylib+0x4a42]  JavaMain+0xab4
  C  [libjli.dylib+0x6fb3]  __JVMInit_block_invoke+0x4b
  C  [Foundation+0x4201c]  __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__+0x7
  C  [Foundation+0x41f14]  -[NSBlockOperation main]+0x62
  C  [Foundation+0x41ea5]  __NSOPERATION_IS_INVOKING_MAIN__+0x11
  C  [Foundation+0x41156]  -[NSOperation start]+0x311
  C  [Foundation+0x804d9]  __NSThreadPerformPerform+0xcc
  C  [CoreFoundation+0x81a0c]  __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__+0x11
  C  [CoreFoundation+0x81974]  __CFRunLoopDoSource0+0xb4
  C  [CoreFoundation+0x816ef]  __CFRunLoopDoSources0+0xf8
  C  [CoreFoundation+0x80121]  __CFRunLoopRun+0x37a
  C  [CoreFoundation+0x7f6ce]  CFRunLoopRunSpecific+0x233
  C  [libjli.dylib+0x65c1]  CreateExecutionEnvironment+0x18f
  C  [libjli.dylib+0x2752]  JLI_Launch+0x54a
  C  [java+0xca1]  main+0x177
  C  [libdyld.dylib+0x15621]  start+0x1
  </code></pre>
  <p>And finally my piece of code that handles the texture creation:</p>
  <pre><code>    // texture stuff
  
      int texture = glGenTextures();
      glActiveTexture(GL_TEXTURE0);
      glBindTexture(GL_TEXTURE_2D, texture);
  
      // load and generate the texture
      glTexImage2D(
              GL_TEXTURE_2D, // target
              0, // highest level of detail
              GL_RGB, // source image bytes per pixel rgb = 3
              image.getWidth(), // width
              image.getHeight(), // height
              0, // ??? must be zero
              GL_RGB, // shader texel layout
              GL_UNSIGNED_BYTE, // size of each color channel
              image.getBuffer() // the data itself, a ByteBuffer wrapping byte[12]
      );
      glGenerateMipmap(GL_TEXTURE_2D);
  
      // set the texture wrapping/filtering options (on the currently bound texture object)
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  
      // toggle on to use lines
      // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  
      // use our nice shader
      glUseProgram(shaderProgram.id);
  
      // set uniforms after activation
      shaderProgram.setInt(&quot;tex&quot;, 0); // why zero? idk
  </code></pre>
  <p>The image class I've created works perfectly fine, the example image I used is 2 by 2 pixels and has an internal buffer of 12 bytes length, so the segvault shouldn't be caused by a too short buffer.</p>