Unsupported operation exception in JME 3.1

Does anyone know how to solve this issue? I’ve never had this happen in JME 3.0.

java.lang.UnsupportedOperationException: Material instances cannot be shared when hardware skinning is used. Ensure all models use unique material instances.
at com.jme3.animation.SkeletonControl.controlRenderHardware(SkeletonControl.java:258)
at com.jme3.animation.SkeletonControl.controlRender(SkeletonControl.java:299)
at com.jme3.scene.control.AbstractControl.render(AbstractControl.java:135)
at com.jme3.scene.Spatial.runControlRender(Spatial.java:756)
at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:723)
at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:733)
at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:733)
at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:733)
at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:712)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1086)
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(Unknown Source)

Could you provide us some code? Important is the part where this exception occurs.

I don’t think I can: the stack trace does not display a single class of mine for some reason. As I’ve mentioned in the original post, this hasn’t occured in JME 3.0.

I’m using JME 3.1 (beta1).

Does the model have a material applied?
All geometries should have a material applied.

This means that 2 models in your scene have the same material applied.

If you’re using hardware skinning (i think this is enabled by default) you have to clone materials for each model that has to use it in the scene.

Now that I took a look I see that .setsetHardwareSkinningPreferred(false); doesn’t crash the app but animated models appear to be disassembled.

Same in scene composer?

I don’t use the JME SDK if that’s what you mean, just Eclipse.

Okay…

This is because you to clone materials for different spatials.

EXAMPLE:

Material mat0=new Material();
geom0.setMaterial(mat0);
geom1.setMaterial(mat0.clone()) //if you don’t clone() the material and you’re using hardware skinning,application crashes.

So the solution is to clone the material for every spatial I use?

If you’re using hardware skinning,that’s probably the solution as far as i know reading the error message.

Oh well but for some reason this wasn’t the case for version 3.0.

The reason is that JME 3.0 didn’t automatically enable hardware skinning.
You can continue by disabling Hardware Skinning but the Perfomance will suck.

Btw: There, where you call spatial.clone() is an overloaded method where you can specify a boolean called alsoCloneMaterial or something.

How do I disable the hardware skinning?

But that’s a worse idea than simply cloning Materials, trust me.

What materials am I supposed to clone? Just the ones used for spatials or also for effects?

Only those who are animated, so not even every spatial.
A hackish approach would be to clone every material on a spatial with an AnimControl attached.

Even though I’ve gone through every class containing animated spatials and made sure to enter basically this method “mesh.setMaterial(mat.clone())” the app still crashed throwing the same exception.