In com.jme.input.Mouse, every time you set a new RenderState that is a TextureState, the mouse will reinitialize the quad. The problem is that quad initialization creates new objects. So changing cursors often results in GC kicking in.
I realize its a very very minor thing and the cursor will not be changed often enough to create major problems. (The reason I found it was stress-testing method that changes cursors). However the fix for it is very simple…
- add a line "initialize(0, 0);" to the Mouse constructor,
- in setRenderState(RenderState rs), change "initialize(imageWidth, imageHeight);" to "resize(imageWidth, imageHeight);"
Thats it… just two lines.
Here is the code after modifications:
public Mouse(String name) {
super(name, 32, 32);
setCullMode(SceneElement.CULL_NEVER);
setRenderQueueMode(Renderer.QUEUE_ORTHO);
setZOrder(Integer.MIN_VALUE);
setLightCombineMode(LightState.OFF);
setTextureCombineMode(TextureState.REPLACE);
initialize(0, 0);
}
public RenderState setRenderState(RenderState rs) {
if (rs.getType() == RenderState.RS_TEXTURE) {
hasCursor = true;
imageHeight = ((TextureState) rs).getTexture().getImage()
.getHeight();
imageWidth = ((TextureState) rs).getTexture().getImage().getWidth();
resize(imageWidth, imageHeight);
hotSpotOffset.set(-imageWidth / 2, imageHeight / 2, 0);
}
return super.setRenderState(rs);
}