Loading texture error

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Loading texture error

GuilhermeAmorim
I need some help here
I trying to load a texture to draw in the screen but I can only get a exception:

java.lang.IndexOutOfBoundsException: Required 196608 remaining bytes in buffer, only had 0
        at com.sun.gluegen.runtime.BufferFactory.rangeCheckBytes(BufferFactory.java:274)
        at com.sun.opengl.impl.GLImpl.glTexImage2D(GLImpl.java:21146)

in this line:

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


I tried to make the buffer have twice the size and the exception is gone, but the texture too, remais only the cube in black.

This is the 1.1.1a version

Thanks for reading
Reply | Threaded
Open this post in threaded view
|

Re: Loading texture error

Michael Bien
sorry but we don't maintain a JOGL 1.x branch.

If the bug still applies to JOGL 2 we will need more information or even better: a self contained testcase.

bugzilla is here:
http://jogamp.org/bugzilla/

thanks,
michael

On 07/04/2010 03:55 PM, GuilhermeAmorim [via jogamp] wrote:
I need some help here
I trying to load a texture to draw in the screen but I can only get a exception:

java.lang.IndexOutOfBoundsException: Required 196608 remaining bytes in buffer, only had 0
        at com.sun.gluegen.runtime.BufferFactory.rangeCheckBytes(BufferFactory.java:274)
        at com.sun.opengl.impl.GLImpl.glTexImage2D(GLImpl.java:21146)

in this line:

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


I tried to make the buffer have twice the size and the exception is gone, but the texture too, remais only the cube in black.

This is the 1.1.1a version

Thanks for reading


View message @ http://jogamp.762907.n3.nabble.com/Loading-texture-error-tp942252p942252.html
To start a new topic under jogamp, email [hidden email]
To unsubscribe from jogamp, click here.


-- 
http://michael-bien.com/
Reply | Threaded
Open this post in threaded view
|

Re: Loading texture error

GuilhermeAmorim
Thanks you for the attention

After sometime reading the documentation I updating the project to the new version of the library I almost cried when the issue reoccurred. hehe

It's strange since I'm learning JOGL with NeHe's Tutorials and they have the JOGL version of this lesson that doesn't work as well
but they posted, so I think it supposedly should work.

Anyway,
I'll post this issue bugzilla, and I'm attaching the code here too.

Any solution would be welcome.

Attachments:
JOGL1.zip

The line that throws the exception is the #99

System: Win7 x64,  Nvidia GeForce 9600 GT, JDK6u20 x32,  JOGL 2 ( GL2 )
Reply | Threaded
Open this post in threaded view
|

Re: Loading texture error

Demoscene Passivist
Administrator
Hi!
I got the same error a while ago. I'm relatively sure the bug lies on ur side. To solve the issue use com.jogamp.opengl.util.texture.Texture/TextureIO to do ur texture handling. Its really easy to use and frees u from the burden of moving the pixel bytes by hand, and as far as I can see in ur code theres no reason why u must use the direct bytebuffer stuff.

Reply | Threaded
Open this post in threaded view
|

Re: Loading texture error

GuilhermeAmorim
Demoscene Passivist wrote
Hi!
I got the same error a while ago. I'm relatively sure the bug lies on ur side. To solve the issue use com.jogamp.opengl.util.texture.Texture/TextureIO to do ur texture handling. Its really easy to use and frees u from the burden of moving the pixel bytes by hand, and as far as I can see in ur code theres no reason why u must use the direct bytebuffer stuff.
Thanks!!

What a shame, I didn't see these classes before!
I can't test right know, but I'll test and return a feedback as soon as possible.
It must solve the problem for real.

and again: Thanks!!!



Reply | Threaded
Open this post in threaded view
|

Re: Loading texture error

Sven Gothel
Administrator
In reply to this post by GuilhermeAmorim
On Monday, July 05, 2010 03:31:43 GuilhermeAmorim [via jogamp] wrote:

>
> Thanks you for the attention
>
> After sometime reading the documentation I updating the project to the new
> version of the library I almost cried when the issue reoccurred. hehe
>
> It's strange since I'm learning JOGL with NeHe's Tutorials and they have the
> JOGL version of this lesson that doesn't work as well
> but they posted, so I think it supposedly should work.
>
> Anyway,
> I'll post this issue bugzilla, and I'm attaching the code here too.
>
> Any solution would be welcome.
>
Thank you.

To not allow any insecure memory access,
we verify all memory/DMA transfers by tracking the approriate state
of the objects. You have experienced this with your posted exception.
.. com.sun.gluegen.runtime.BufferFactory.rangeCheckBytes

I fetched your attachment, made the little conversion necessary for JOGL2
(sun -> jogamp, and the BufferUtils -> Buffer), plus added the debug and trace pipeline.
See attachement #1.

This shows me the following:

+++

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() solved your bug, so we can read all required bytes,
see attachment #2.

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 :)

~Sven


> Attachments:
> http://jogamp.762907.n3.nabble.com/file/n943281/JOGL1.zip JOGL1.zip
>
> ______________________________________

Main-1.diff (1K) Download Attachment
Main-2.diff (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Loading texture error

GuilhermeAmorim
Both methods worked fine and now I can move on to the next level, I mean, nehes lesson :D

I love jogl, it's really simple to use with some practise.

Thaaaank you from the bottom of my heart!! :DDD
Reply | Threaded
Open this post in threaded view
|

Re: Loading texture error

NickJPGeorge
In reply to this post by Demoscene Passivist
Sorry for being thick, but is there a guide somewhere for using textureio?  I searched but did not find.

Thanks,
Reply | Threaded
Open this post in threaded view
|

Re: Loading texture error

Demoscene Passivist
Administrator
Other than the JavaDoc for TextureIO (wich can be found here) u can take a look at my TextureUtils class wich uses TextureIO to load/bind textures on github.