From 92b5d40003e3c99059f8b2025ed028af19548a1e Mon Sep 17 00:00:00 2001 From: Paul Speed Date: Sun, 4 Dec 2016 20:35:49 -0500 Subject: [PATCH] Modified BitmapTextPage to always deep clone its mesh since otherwise BitmapText objects end up sharing them and that's bad. --- .../java/com/jme3/font/BitmapTextPage.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/font/BitmapTextPage.java b/jme3-core/src/main/java/com/jme3/font/BitmapTextPage.java index 82d27aa65..0df557906 100644 --- a/jme3-core/src/main/java/com/jme3/font/BitmapTextPage.java +++ b/jme3-core/src/main/java/com/jme3/font/BitmapTextPage.java @@ -38,10 +38,12 @@ import com.jme3.scene.VertexBuffer; import com.jme3.scene.VertexBuffer.Type; import com.jme3.texture.Texture2D; import com.jme3.util.BufferUtils; +import com.jme3.util.clone.Cloner; import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.ShortBuffer; import java.util.LinkedList; +import java.util.LinkedList; /** * One page per BitmapText Font Texture. @@ -119,10 +121,29 @@ class BitmapTextPage extends Geometry { @Override public BitmapTextPage clone() { BitmapTextPage clone = (BitmapTextPage) super.clone(); - clone.mesh = mesh.deepClone(); + //clone.mesh = mesh.deepClone(); return clone; } + /** + * Called internally by com.jme3.util.clone.Cloner. Do not call directly. + */ + @Override + public void cloneFields( Cloner cloner, Object original ) { + + Mesh originalMesh = this.mesh; + + super.cloneFields(cloner, original); + + // BitmapTextPage always requires a new mesh or different + // BitmapText instances will clobber one another. + // But if we were already deep cloning meshes then we don't + // want to do it again... so we'll check first. + if( this.mesh == originalMesh ) { + this.mesh = mesh.deepClone(); + } + } + // Here is where one might add JmeCloneable related stuff except // the old clone() method doesn't actually bother to clone anything. // The arrays and the pageQuads are shared across all BitmapTextPage