Unexpected ArrayIndexOutOfBoundsException in JavaFX application, refering to no array

Posted by Eugene on Stack Overflow See other posts from Stack Overflow or by Eugene
Published on 2013-11-04T14:28:51Z Indexed on 2013/11/04 15:54 UTC
Read the original article Hit count: 205

Filed under:
|
|
|

I have the following code:

 public void setContent(Importer3D importer) {
    if (DEBUG) {
        System.out.println("Initialization of Mesh's arrays");
    }
    coords = importer.getCoords();
    texCoords = importer.getTexCoords();
    faces = importer.getFaces();
    if (DEBUG) {
        System.out.println("Applying Mesh's arrays");
    }
    mesh = new TriangleMesh();
    mesh.getPoints().setAll(coords);
    mesh.getTexCoords().setAll(texCoords);
    mesh.getFaces().setAll(faces);
    if (DEBUG) {
        System.out.println("Initialization of the material");
    }
    initMaterial();
    if (DEBUG) {
        System.out.println("Setting the MeshView");
    }
    meshView.setMesh(mesh);
    meshView.setMaterial(material);
    meshView.setDrawMode(DrawMode.FILL);
    if (DEBUG) {
        System.out.println("Adding to 3D scene");
    }
    root3d.getChildren().clear();
    root3d.getChildren().add(meshView);
    if (DEBUG) {
        System.out.println("3D model is ready!");
    }
}

The Imporeter3D class part:

  private void load(File file) {

    stlLoader = new STLLoader(file);
}

public float[] getCoords() {
    return stlLoader.getCoords();
}

public float[] getTexCoords() {
    return stlLoader.getTexCoords();
}

public int[] getFaces() {
    return stlLoader.getFaces();
}

The STLLoader:

public class STLLoader{
public STLLoader(File file) {
    stlFile = new STLFile(file);
    loadManager = stlFile.loadManager;
    pointsArray = new PointsArray(stlFile);
    texCoordsArray = new TexCoordsArray();
}

public float[] getCoords() {
    return pointsArray.getPoints();
}

public float[] getTexCoords() {
    return texCoordsArray.getTexCoords();
}

public int[] getFaces() {
    return pointsArray.getFaces();
}

private STLFile stlFile;
private PointsArray pointsArray;
private TexCoordsArray texCoordsArray;
private FacesArray facesArray;
public  SimpleBooleanProperty finished = new SimpleBooleanProperty(false);
public LoadManager loadManager;}

PointsArray file:

public class PointsArray {
public PointsArray(STLFile stlFile) {
    this.stlFile = stlFile;
    initPoints();
}

private void initPoints() {
    ArrayList<Double> pointsList = stlFile.getPoints();
    ArrayList<Double> uPointsList = new ArrayList<>();


    faces = new int[pointsList.size()*2];
    int n = 0;
    for (Double d : pointsList) {
        if (uPointsList.indexOf(d) == -1) {
            uPointsList.add(d);
        }
        faces[n] = uPointsList.indexOf(d);
        faces[++n] = 0;
        n++;
    }
    int i = 0;

    points = new float[uPointsList.size()];
    for (Double d : uPointsList) {
        points[i] = d.floatValue();
        i++;
    }
}

public float[] getPoints() {
    return points;
}

public  int[] getFaces() {
    return faces;
}

private float[] points;
private int[] faces;
private STLFile stlFile;
public static boolean DEBUG = true;

}

And STLFile:

    ArrayList<Double> coords = new ArrayList<>();
double temp;
private void readV(STLParser parser) {
    for (int n = 0; n < 3; n++) {
        if(!(parser.ttype==STLParser.TT_WORD && parser.sval.equals("vertex"))) {
            System.err.println("Format Error:expecting 'vertex' on line " + parser.lineno());
        } else {
            if (parser.getNumber()) {
                temp = parser.nval;
                coords.add(temp);
                if(DEBUG) {
                    System.out.println("Vertex:");
                    System.out.print("X=" + temp + " ");
                }

                if (parser.getNumber()) {
                    temp = parser.nval;
                    coords.add(temp);
                    if(DEBUG) {
                        System.out.print("Y=" + temp + " ");
                    }

                    if (parser.getNumber()) {
                        temp = parser.nval;
                        coords.add(temp);
                        if(DEBUG) {
                            System.out.println("Z=" + temp + " ");
                        }


                        readEOL(parser);
                    } else System.err.println("Format Error: expecting coordinate on line " + parser.lineno());
                } else System.err.println("Format Error: expecting coordinate on line " + parser.lineno());
            } else System.err.println("Format Error: expecting coordinate on line " + parser.lineno());
        }
        if (n < 2) {
            try {
                parser.nextToken();
            } catch (IOException e) {
                System.err.println("IO Error on line " + parser.lineno() + ": " + e.getMessage());
            }
        }
    }

}

public ArrayList<Double> getPoints() {
    return coords;
}

As a result of all of this code, I expected to get 3d model in MeshView. But the present result is very strange: everything works and in DEBUG mode I get 3d model is ready! from setContent(), and then unexpected ArrayIndexOutOfBoundsException:

File readed
Initialization of Mesh's arrays
Applying Mesh's arrays
Initialization of the material
Setting the MeshView
Adding to 3D scene
3D model is ready!
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 32252
    at com.sun.javafx.collections.ObservableFloatArrayImpl.rangeCheck(ObservableFloatArrayImpl.java:276)
    at com.sun.javafx.collections.ObservableFloatArrayImpl.get(ObservableFloatArrayImpl.java:184)
    at javafx.scene.shape.TriangleMesh.computeBounds(TriangleMesh.java:262)
    at javafx.scene.shape.MeshView.impl_computeGeomBounds(MeshView.java:151)
    at javafx.scene.Node.updateGeomBounds(Node.java:3497)
    at javafx.scene.Node.getGeomBounds(Node.java:3450)
    at javafx.scene.Node.getLocalBounds(Node.java:3432)
    at javafx.scene.Node.updateTxBounds(Node.java:3510)
    at javafx.scene.Node.getTransformedBounds(Node.java:3350)
    at javafx.scene.Node.updateBounds(Node.java:516)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.SubScene.updateBounds(SubScene.java:556)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.Parent.updateBounds(Parent.java:1668)
    at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2309)
    at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:329)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:479)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:459)
    at com.sun.javafx.tk.quantum.QuantumToolkit$13.run(QuantumToolkit.java:326)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:101)
    at java.lang.Thread.run(Thread.java:724)
Exception in thread "JavaFX Application Thread" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 32252
    at com.sun.javafx.collections.ObservableFloatArrayImpl.rangeCheck(ObservableFloatArrayImpl.java:276)
    at com.sun.javafx.collections.ObservableFloatArrayImpl.get(ObservableFloatArrayImpl.java:184)

The stranger thing is that this stack doesn't stop until I close the program. And moreover it doesn't point to any my array. What is this? And why does it happen?

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays