Bug in cg ?

When using CgGL.cgGLSetMatrixParameterArrayfc() I always get index out of bound errors. I’ve tested it on GF3 and Radeon 9800PRO.

However CgGL.cgGLSetParameterArray4f() works.

One more thing, why are only float[] arrays supported and not NIO ?

Cheers
// Tomas :slight_smile:

What’s the exact error you’re seeing? I don’t see how an ArrayIndexOutOfBoundsException can be raised in CgGL.cgGLSetMatrixParameterArrayfc(). I can see how a native code crash might happen, but not an ArrayIndexOutOfBoundsException.

I’m not sure why GlueGen isn’t producing NIO variants of the Cg routines. Could you file a bug with the JOGL Issue Tracker? Thanks.

It’s cg error code 23, CG_OUT_OF_ARRAY_BOUNDS_ERROR, and message of getErrorString() is roughly "indexing is out of bounds.

I can post the correct words when I’ll get back to work tomorrow.

Ok here we go, the Java code looks like this:



float[] matrixBuffer = new float[16]; /Also tested with bigger arrays ;)   
                    CgGL.cgGLSetMatrixParameterArrayfc(cgParameter,0,1, matrixBuffer);

// Both these methods results in the same  error
//CgGL.cgGLSetMatrixParameterArrayfc(cgParameter,0,0, matrixBuffer);
//CgGL.cgGLSetMatrixParameterArrayfc(cgParameter,0,16, matrixBuffer);



…and the vertex shader like this:



void main(float4 pos : POSITION,
              uniform float4x4 modelViewProjection,
              uniform float4x4 matrixBuffer[1],
              out float4 opos : POSITION
              ){
            
            opos = mul(modelViewProjection, pos);
}

Cg then reports this error.

Error code = 23, which is CG_OUT_OF_ARRAY_BOUNDS_ERROR
CgGetErrorString = Index into the array is out of bounds.

It seems like and empty array is assigned on the JNI side.

// Tomas

… or is this some kind of profile problem ?!?.

I think it is probably a bug in the Cg runtime, not in the JOGL binding. We do almost no work in the JNI code associated with that method and I think it’s unlikely that something is broken in it. Do you have the time to try to make a C version of your example?

I’ll try that next week and let you know. I’m currently very busy with the next release of AgentFX.

// Tomas

Hi,

Was there ever a solution to this? I have run into exactly the same problem with JOGL 1.1.1 and the Cg Toolkit 1.2.1.

I am trying to use the “Advanced Skinning” example from the Cg Toolkit manual - does anyone know where I can get the OpenGL C/C++ code that goes with this example?

If it really is a bug in Cg, will moving to 1.4 help or is there a workaround? It looks like I will have to migrate to JSR231 to be able to use Cg 1.4 and I want to try and avoid that right now.

Kevin

I never found a solution to this issue and we where forced to do a workaround. Instead of passing in an array of matrices you can assign four Float4 arrays and combine them in the shader to a matrix. I haven’t tried this on Cg1.4 and JSR231 so I don’t know if this still is an issue.

Good Luck
// Tomas

I considered your suggestion and decided to choose the lesser of the two evils and migrated to JSR-231. I can confirm that there is no longer a problem with cgGLSetMatrixParameterArrayfc using JSR231 beta 3 and the nVidia Cg toolkit 1.4 :slight_smile:

Thanks for your help

Kevin