Bug 402 - Texture Buffer Size
Summary: Texture Buffer Size
Status: VERIFIED INVALID
Alias: None
Product: Jogl
Classification: JogAmp
Component: opengl (show other bugs)
Version: 2
Hardware: pc_x86_64 windows
: --- major
Assignee: Sven Gothel
URL:
Depends on:
Blocks:
 
Reported: 2010-07-04 18:42 CEST by Guilherme Amorim
Modified: 2010-07-06 05:56 CEST (History)
0 users

See Also:
Type: ---
SCM Refs:
Workaround: ---


Attachments
Zip containing code that throws the exception and the Image file (27.40 KB, application/x-zip-compressed)
2010-07-04 18:43 CEST, Guilherme Amorim
Details
Exception Description (2.27 KB, text/plain)
2010-07-04 18:49 CEST, Guilherme Amorim
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Guilherme Amorim 2010-07-04 18:42:11 CEST
While loading the texture the following exception may occur:

javax.media.opengl.GLException: java.lang.IndexOutOfBoundsException: Required 196608 remaining bytes in buffer, only had 0
at com.sun.gluegen.runtime.BufferFactory.rangeCheckBytes(BufferFactory.java:311)
        at com.sun.opengl.impl.gl2.GL2Impl.glTexImage2D(GL2Impl.java:18663)
...

The following line cause the exception:

gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, 3, img.getWidth(), img.getHeight(), 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, buffer);

"buffer" is a ByteBuffer variable which holds data from a BufferedImage


The whole code is attached

Thanks
Comment 1 Guilherme Amorim 2010-07-04 18:43:53 CEST
Created attachment 145 [details]
Zip containing code that throws the exception and the Image file
Comment 2 Guilherme Amorim 2010-07-04 18:49:03 CEST
Created attachment 146 [details]
Exception Description
Comment 3 Sven Gothel 2010-07-06 05:56:26 CEST
After minor test case fixes to allow it to run under JOGL2,
plus adding trace and debug pipeline, the output is:

+++

Info: XInitThreads() called for concurrent Thread support
glGenTextures(<int> 0x1, <[I>, <int> 0x0)
glBindTexture(<int> 0xDE1, <int> 0x1)
glTexImage2D(<int> 0xDE1, <int> 0x0, <int> 0x3, <int> 0x100, <int> 0x100, <int> 0x0, <int> 0x1907, <int> 0x1401, <java.nio.Buffer> java.nio.DirectByteBuffer[pos=196608 lim=196608 cap=196608])Exception in thread "Timer-0" javax.media.opengl.GLException: java.lang.IndexOutOfBoundsException: Required 196608 remaining bytes in buffer, only had 0

+++

As you can see, we calculate the proper byte size of 196608, which is to be expected,
but you buffer can't offer any - since it's position is at it's limit.

A simple "buffer.rewind()" before passing it to the GL texture funtion solves your bug, 
so we can read all required bytes,

Now the output is:

+++

Info: XInitThreads() called for concurrent Thread support
glGenTextures(<int> 0x1, <[I>, <int> 0x0)
glBindTexture(<int> 0xDE1, <int> 0x1)
glTexImage2D(<int> 0xDE1, <int> 0x0, <int> 0x3, <int> 0x100, <int> 0x100, <int> 0x0, <int> 0x1907, <int> 0x1401, <java.nio.Buffer> java.nio.DirectByteBuffer[pos=0 lim=196608 cap=196608])
glTexParameteri(<int> 0xDE1, <int> 0x2801, <int> 0x2601)
glTexParameteri(<int> 0xDE1, <int> 0x2800, <int> 0x2600)
glShadeModel(<int> 0x1D01)
...

+++

And the cube is no more yellow :)