From 65833bbcec423f9741116dc9b785e6954f2fcec7 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 16 Aug 2013 03:35:06 +0200 Subject: Fix Bug 817 (1/2): GLPixelAttributes checks arguments and queried bytesPerPixel GLPixelAttributes checks arguments (componentCount, format / type) and the queried bytesPerPixel. --- src/jogl/classes/com/jogamp/opengl/util/GLPixelBuffer.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/jogl/classes/com/jogamp/opengl') diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLPixelBuffer.java b/src/jogl/classes/com/jogamp/opengl/util/GLPixelBuffer.java index 2bd45e3e4..e9853cc31 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLPixelBuffer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLPixelBuffer.java @@ -32,6 +32,7 @@ import java.nio.ByteBuffer; import javax.media.opengl.GL; import javax.media.opengl.GLContext; +import javax.media.opengl.GLException; import com.jogamp.common.nio.Buffers; import com.jogamp.opengl.util.texture.TextureData; @@ -128,7 +129,7 @@ public class GLPixelBuffer { /** Pixel attributes. */ public static class GLPixelAttributes { /** Undefined instance of {@link GLPixelAttributes}, having componentCount:=0, format:=0 and type:= 0. */ - public static final GLPixelAttributes UNDEF = new GLPixelAttributes(0, 0, 0); + public static final GLPixelAttributes UNDEF = new GLPixelAttributes(0, 0, 0, false); /** Pixel source component count, i.e. number of meaningful components. */ public final int componentCount; @@ -154,10 +155,21 @@ public class GLPixelBuffer { * @param dataType GL data type */ public GLPixelAttributes(int componentCount, int dataFormat, int dataType) { + this(componentCount, dataFormat, dataType, true); + } + private GLPixelAttributes(int componentCount, int dataFormat, int dataType, boolean checkArgs) { this.componentCount = componentCount; this.format = dataFormat; this.type = dataType; this.bytesPerPixel = ( 0 < dataFormat && 0 < dataType ) ? GLBuffers.bytesPerPixel(dataFormat, dataType) : 0; + if( checkArgs ) { + if( 0 == componentCount || 0 == format || 0 == type ) { + throw new GLException("Zero components, format and/or type: "+this); + } + if( 0 == bytesPerPixel ) { + throw new GLException("Zero bytesPerPixel: "+this); + } + } } public String toString() { return "PixelAttributes[comp "+componentCount+", fmt 0x"+Integer.toHexString(format)+", type 0x"+Integer.toHexString(type)+", bytesPerPixel "+bytesPerPixel+"]"; -- cgit v1.2.3