LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: shaddow on February 23, 2012, 16:58:56

Title: BufferSizeException glLoadMatrix
Post by: shaddow on February 23, 2012, 16:58:56
Hi there,

I recently switched from JOGL to LWJGL and I'm currently porting my engine.
Sadly I encountered the following problem:


QuoteCreating 16 buffer
16 capacity, 0 remaining, 16 position, .. flipping..
flipped
16 capacity, 16 remaining, 0 position
Exception in thread "main" java.lang.IllegalArgumentException: Number of remaining buffer elements is 4, must be at least 16. Because at most 16 elements can be returned, a buffer with at least 16 elements is required, regardless of actual returned element count
   at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162)
   at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189)
   at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:244)
   at org.lwjgl.opengl.GL11.glGetInteger(GL11.java:1355)

Please note the debug statements, where i create a floatbuffer from my camera matrix. Nonetheless, this error keeps occuring. As far as google told me, this error was supposed to be resolved by flipping the floatbuffer, but i already did so:

   glLoadIdentity();

   System.out.println("Creating "+(entity.getMatrix().get().length)+" buffer");
   FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(entity.getMatrix().get().length);
   floatBuffer.put(entity.getMatrix().get());
       System.out.println(floatBuffer.capacity()+" capacity, "+ floatBuffer.remaining()+" remaining, "+ floatBuffer.position()+" position, .. flipping..");
   floatBuffer.flip();
   
       System.out.println("flipped");
       System.out.println(floatBuffer.capacity()+" capacity, "+ floatBuffer.remaining()+" remaining, "+ floatBuffer.position()+" position");

   glLoadMatrix(floatBuffer);


Thank you for your help.

Title: Re: BufferSizeException glLoadMatrix
Post by: spasi on February 23, 2012, 18:33:08
Quote from: shaddow on February 23, 2012, 16:58:56
QuoteCreating 16 buffer
16 capacity, 0 remaining, 16 position, .. flipping..
flipped
16 capacity, 16 remaining, 0 position
Exception in thread "main" java.lang.IllegalArgumentException: Number of remaining buffer elements is 4, must be at least 16. Because at most 16 elements can be returned, a buffer with at least 16 elements is required, regardless of actual returned element count
   at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162)
   at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189)
   at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:244)
   at org.lwjgl.opengl.GL11.glGetInteger(GL11.java:1355)

See the last line, the error comes from glGetInteger, not glLoadMatrix.
Title: Re: BufferSizeException glLoadMatrix
Post by: shaddow on February 25, 2012, 22:24:09
Damn it. I have been so focused on using the right buffer and checking not to use any jogl libs, that i totally overlooked the error resulting from a totally different part of the application..

However, i got my first demo apps running on lwjgl and so far i'm very pleased with the api ;)