Bug fix for Mesh.deepClone()

First of all I thought it was a bug in BatchNode, as I was getting a buffer overflow error using simple Quads, but as I debugged it to:

Line 467 of BatchNode
[java]totalVerts += geom.getVertexCount();[/java]

and wondered why my totalVerts was actually getting smaller each loop, I knew the error must be somewhere else. Then I tracked it down to Mesh.deepClone():

clone.vertCount = -1;
clone.elementCount = -1;

Here’s the diff for Mesh.java:
[java]# This patch file was generated by NetBeans IDE

It uses platform neutral UTF-8 encoding and \n newlines.

— Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -240,8 +240,8 @@

         clone.vertexArrayID = -1;
  •        clone.vertCount = -1;
  •        clone.elementCount = -1;
  •        clone.vertCount = vertCount;
  •        clone.elementCount = elementCount;
           // although this could change
           // if the bone weight/index buffers are modified[/java]

Here’s a testcase:
package com.wezgui;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.scene.BatchNode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.shape.Quad;


  • @author Wesley
    public class TestDeepClone extends SimpleApplication {

    public static void main(String[] args) {
    new TestDeepClone().start();

    public void simpleInitApp() {

     Quad q = new Quad(1, 1);
     Geometry g = new Geometry("q", q);
     Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
     // Create a deepClone
     Mesh q1 = q.deepClone();
     Geometry g1 = new Geometry("q", q1);
     g1.move(2, 0, 0);
     BatchNode node = new BatchNode("batch");
     node.batch();   // <--- Fails here


It may also fix the bizarre behavior seen here by @Kaizo (although I haven’t checked):


thanks for this

1 Like

Wow good work. :mrgreen:
I should maybe try the deepClone with a future version then.

1 Like

The issue is fixed in JME trunk at rev 11080.