Issue with VarType.IntArray

I just ran into something that is preventing me from passing a uniform array of integers to my shader as a VarType.IntArray. For now I was able to get around this bug by using a FloatArray and casting my floats to an integer in the shader, but I thought I should still report this issue in case it’s a bug

Whenever I was using an array of integers, only the value at index [0] seems to hold its value after being passed to the shader. I tested this by looping through my array and printing out each integer value right before the line of code where I pass the IntArray to the shader. Based on this output, all of the integers in the array were returning the correct value I had just assigned on the java end of things.

So then I also looped through my values in the shader, displaying a different texture based on the integer value, and each integer above the [0] index appears to show the wrong texture, suggesting that the data is somehow different than what I set it to be prior to passing it to the shader.

I initially thought this was something I was doing by mistake, but after 2-3 hours of troubleshooting and ‘proof-reading’ my code with no success, I decided to just use a FloatArray and cast that to an integer in the shader and was surprised to find my data is now correct and consistent on both the Java and GLSL side of things.

Could you post your test case by any chance?

Yes of course, I tried narrowing it down to the important parts, since I was just modifying my main project to print out the array values in this test case.

Right before I pass the IntArray to the shader, I added this loop to print out the values of my array on the java end. I also filled the array with a default value of -1 with Arrays.fill()

                       Arrays.fill(effectAlbedoMapIds, -10);
                       effectAlbedoMapIds[0] = 2;
                       effectAlbedoMapIds[1] = 2;

                        afflictedMat.setParam("TextureEffects", VarType.TextureArray, textureArray);
                        afflictedMat.setParam("TextureEffectAlbedoId", VarType.IntArray, effectAlbedoMapIds);
                        for(int p = 0; p < effectAlbedoMapIds.length; p++){
                            int in = effectAlbedoMapIds[p];
                            if(in > -1){ 
                                 System.out.println("index " + p + "     integer: " + in);

This is the outpout to the console, showing that the value 2 is stored in both:

index 0 integer: 2
index 1 integer: 2

Here is the code in my shader’s .frag file responsible for picking a texture from the TextureArray based on the IntArray I’m trying to pass.

             uniform int m_TextureEffectAlbedoId[40];
            //uniform float m_TextureEffectAlbedoId[40];  

        #ifdef TEXTUREEFFECTS
           uniform sampler2DArray m_TextureEffects;

        for(int i = 0; i < 40; i++){

                int texArrayAlbedoId = int(m_TextureEffectAlbedoId[i]);
                effectColor = texture2D(m_TextureEffects, vec3(effectTexCoords, texArrayAlbedoId));


But when I run my application using the IntArray, the two effects that should both be using the texture with ID = 2 are showing different textures:

It also looks like the inaccurate integer values will always be equal to the default value they were filled with using Arrays.fill(), except for the first effect that I try to create. The integer at index [0] seems to be the only part of the array that stores the value I set.

And If I change 4 lines of code between my shader and java file to replace the IntArray with a FloatArray, then the output texture appears to be conistent with the integer it was intended to be set as: