Workaround for "Material instances cannot be shared when hardware skinning is used."?

On Xbuf loader, when I try to play some animation I got the following exception :

java.lang.UnsupportedOperationException: Material instances cannot be shared when hardware skinning is used. Ensure all models use unique material instances.

coming from (I copied SkeletonControl from 3.1 a month ago, and use it for jME 3.0): SkeletonControl_31.java

    private void controlRenderHardware() {
        offsetMatrices = skeleton.computeSkinningMatrices();
        for (Material m : materials) {
            MatParam currentParam = m.getParam("BoneMatrices");
            if (currentParam != null) {
                if (currentParam.getValue() != offsetMatrices) {
                    // Check to see if other SkeletonControl
                    // is operating on this material, in that case, user
                    // is sharing materials between models which is NOT allowed
                    // when hardware skinning used.
                    throw new UnsupportedOperationException(
                            "Material instances cannot be shared when hardware skinning is used. " +
                            "Ensure all models use unique material instances : " + m.getName()
                    );
                }
            }            
            m.setParam("BoneMatrices", VarType.Matrix4Array, offsetMatrices);
        }
    }

I tried to workaround by cloning Material on Geometry :

    def void cloneMaterialOnGeometry(Spatial v) {
        if (v instanceof Geometry) {
            v.material = v.material.clone()
            v.material.clearParam("BoneMatrices")
        } else if (v instanceof Node) {
            for (child : v.children) {
                cloneMaterialOnGeometry(child)
            }
        }        
    }

I no longer have the Exception, but now when I play any animation of the model, it seems to always play the same animation (the first I register). I’ll check that with other model.

Question: Is it the right workaround ? Any advices for the xbuf “loader” ?

Theres no point in cloning materials.

I don’t understand ? material.clone doesn’t create a clone (I didn’t check the source code) ?

Yes but there is no point in creating a clone, just make separate material instances.

I feel like a noob. What is the difference between Material’s instance, and the result of a method that “clone/copy” a Material ?

There is no cloning involved here… two SkeletonControls are modifying the SAME Material instance as one control detects that another control has modified the same material parameter.

I’ll investigate deeper. The sample I’m working on should have only one skeleton, and share a default Material for every Geometry.

More info, when I’ll back to home.

EDIT: I forgot, the skeleton is applied on a parent node of the geometries (can be several). I cloned the Material instance per each geometry so each one can have it’s own Material instance to cache “BoneMatrices”.

Material.clone create a new instance of the Material and duplicate Params like I excepte. So I don’t understand why it’s not the solution.