Bug 463 - GLUgl2.gluScaleImage() consumes all memory
Summary: GLUgl2.gluScaleImage() consumes all memory
Status: VERIFIED FIXED
Alias: None
Product: Jogl
Classification: JogAmp
Component: opengl (show other bugs)
Version: 2
Hardware: All all
: --- enhancement
Assignee: Sven Gothel
URL:
Depends on:
Blocks:
 
Reported: 2011-01-24 23:52 CET by Wade Walker
Modified: 2011-02-02 21:31 CET (History)
1 user (show)

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


Attachments
JOGL 2 unit test (2.23 KB, text/plain)
2011-01-24 23:53 CET, Wade Walker
Details
JOGL 1 unit test (2.17 KB, text/plain)
2011-01-24 23:54 CET, Wade Walker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wade Walker 2011-01-24 23:52:39 CET
A simple call to GLUgl2.gluScaleImage() can consume all memory. For example:

int widthin = 559;
int heightin = 425;
        
int widthout = 1024;
int heightout = 512;
        
int textureInLength = widthin * heightin * 4;
int textureOutLength = widthout * heightout * 4;
        
byte[] datain = new byte[textureInLength];
byte[] dataout = new byte[textureOutLength];
        
ByteBuffer bufferIn  = ByteBuffer.wrap(datain);
ByteBuffer bufferOut = ByteBuffer.wrap(dataout);      
GLUgl2 glu = new GLUgl2();
glu.gluScaleImage( GL.GL_RGBA,
                   widthin, heightin, GL.GL_UNSIGNED_BYTE, bufferIn,
                   widthout, heightout, GL.GL_UNSIGNED_BYTE, bufferOut );

This runs out of memory on an 8GB machine within seconds, then starts paging.

CentOS 5.4, x86_64, Java 1.6.0_21-b06, JOGL autobuild b266.
Comment 1 Wade Walker 2011-01-24 23:53:43 CET
Created attachment 222 [details]
JOGL 2 unit test
Comment 2 Wade Walker 2011-01-24 23:54:24 CET
Created attachment 223 [details]
JOGL 1 unit test
Comment 3 Wade Walker 2011-01-24 23:58:37 CET
Problem identified in Type_Widget. In JOGL 1, the constructor was:

public Type_Widget() {
    buffer = ByteBuffer.allocate( 4 );
}

In JOGL 2, it's this:

public Type_Widget() {
    buffer = ByteBuffer.allocateDirect( 4 );
}

When I change it back to how it was in JOGL 1, the unit test no longer eats all memory and crashes. Apparently creating these direct buffers inside the inner loops of Image.fill_image() and Image.empty_image() is more than the JVM can handle for some reason. With this fix, the unit test consumes hardly any memory; without the fix, it eats > 6GB before hitting the page file.

I'll submit the JOGL2 unit test and fix as a pull request shortly.
Comment 4 Sven Gothel 2011-02-02 21:31:29 CET
merged, passed in #280