[SOLVED]Weird problem with materials in jme 3.1 alpha 5

Hi

this is simple test code :

   public void simpleInitApp() {
         Sphere s1=new Sphere(15, 20, 3);                 
        Geometry geom = new Geometry("Sphere1", s1);      
     
        Material mat = new Material(assetManager, 
              "Common/MatDefs/Light/Lighting.j3md");
        mat.setBoolean("UseMaterialColors", true);
        mat.setColor("Diffuse", new ColorRGBA(1, 1, 200, 0.5f));
        mat.setColor("Ambient", ColorRGBA.White);
        mat.setColor("Specular", new ColorRGBA(1, 1, 1, 0.5f));
        
        mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
      
        geom.setMaterial(mat);                        // assign the material to geometry
        geom.setQueueBucket(Bucket.Transparent);
        rootNode.attachChild(geom);                   // make geometry appear in scene
    
        Sphere s2=new Sphere(15, 20, 1);
        Geometry geom2=new Geometry("Sphere2",s2);
        Material mat2 = new Material(assetManager, 
              "Common/MatDefs/Light/Lighting.j3md"); // create a simple material
        mat2.setBoolean("UseMaterialColors", true);
        mat2.setColor("Diffuse", ColorRGBA.Orange);
        mat2.setColor("Ambient", ColorRGBA.White);
        mat2.setColor("Specular", new ColorRGBA(1, 1, 1, 0.5f));
        
      
        geom2.setMaterial(mat2);                        // assign the material to geometry
        
        rootNode.attachChild(geom2);                   

 /** A white, directional light source */ 
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f)).normalizeLocal());
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun); 
    }

the problem is if i remove this line :
mat.setColor("Ambient", ColorRGBA.White);
but keep this line :
mat2.setColor("Ambient", ColorRGBA.White);
(or vice verse)

I will get this exception at run time:

       java.lang.ClassCastException: com.jme3.math.Vector4f cannot be cast to com.jme3.math.ColorRGBA
    at com.jme3.shader.Uniform.setValue(Uniform.java:323)
    at com.jme3.material.Material.updateShaderMaterialParameters(Material.java:804)
    at com.jme3.material.Material.render(Material.java:960)
    at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:616)
    at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
    at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:305)
    at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:870)
    at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:781)
    at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1097)
    at com.jme3.renderer.RenderManager.render(RenderManager.java:1145)
    at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
    at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
    at java.lang.Thread.run(Thread.java:745)

but if i remove both of them or keep both of them it will work with out exception.

the same will happen for
.setColor("Specular", new ColorRGBA(1, 1, 1, 0.5f));

and

.setColor("Diffuse", ...));

it works fine in 3.1 alpha 4 .

Wow… that’s bad ju-ju.

Must be related to the material code changes I guess.

I will appreciate if someone also test it on his/her jme alpha 5 to see if it goes wrong ? please.
Just to be sure if it is a bug or just some mistake of mine.

really looks like a bug to me

Can anybody else reproduce the bug with the test case? It works for me…

Sorry to ask this but do you make sure to comment this line before running ?
//mat.setColor("Ambient", ColorRGBA.White);

Ah got it now. Thanks.

It’s fixed:

2 Likes

@Momoko_Fan thanks for fixing that.:heart:

Also thanks from @gembutterfly because his post helped to find the bug .:heart: