world.removeObject(Object3D) crash

Started by LemonLake, October 04, 2013, 08:24:22 PM

Previous topic - Next topic

LemonLake

I have a bunch of tiles in my world (a 16x16 array for now, but only a circle of them are created) and some have houses on them. In the array is a Tile object, which holds the tile information such as the height, the tile model (a hexagon) and it's child if it has one. The tile position is stored in the model's name so I can access it through picking. In a touch event, I am removing the house of the tile if it has one, using this code:
    String name = ((Object3D) res[1]).getName();
    int foundTileX = Integer.parseInt(name.replace("Tile_", "").split(";")[0]);
    int foundTileY = Integer.parseInt(name.replace("Tile_", "").split(";")[1]);
    Tile foundTile = map.tiles[foundTileX][foundTileY];
    if(foundTile.child!=null){
    world.removeObject(foundTile.child);
    foundTile.child=null;
    }

However, as soon as a house is removed, the game crashes with this error:

I believe it happens because the touchEvent happens after the world stuff and before the rendering.
How can I solve this? Thanks

EgonOlsen

You can solve this by not doing the removal in the touch event but in the rendering thread (i.e. in onDrawFrame()). As mentioned many times around here, jPCT isn't thread safe. Your problem so common, it even has a wiki page... ;) http://www.jpct.net/wiki/index.php/Nullpointer_during_rendering_and/or_collision_detection

LemonLake

So if I create a queue of the things to remove, I can then remove that in the rendering thread and empty the queue and all should be good?

EgonOlsen


LemonLake

#4
I'm having an issue with this; it's treating every tile as if it's named Tile_10;15 during the rendering process, I've tried calculating through the tiles four different ways; two in the touch event and two in the rendering event.
This is my code in the rendering event that looks at the tiles to determine which one was touched:
if (tileChildRemoveQueue.size() > 0) {
for (String name : tileChildRemoveQueue) {
for (int y = 0; y < map.tiles[1].length; y++) {
for (int x = 0; x < map.tiles.length; x++) {
if (map.tiles[x][y].air){
continue;
}
if (map.tiles[x][y].hexagon.getName().equalsIgnoreCase(name)) {
System.out.println("Found one! Details:");
System.out.println("loop x: " + x + " loop y: " + y + " queue name: " + name);
System.out.println("hex name: " + map.tiles[x][y].hexagon.getName());
System.out.println("has child? " + map.tiles[x][y].child != null);
if (map.tiles[x][y].child != null) {
world.removeObject(map.tiles[x][y].child);
map.tiles[x][y].child = null;
}
}else{
System.out.println("fail. x: "+x+" y: "+y+ " requested name: "+name+" got name: "+map.tiles[x][y].hexagon.getName());
}
}
}
}
tileChildRemoveQueue.clear();
}


This is the code in the touch event:
                                SimpleVector dir = Interact2D.reproject2D3DWS(cam, fb, (int) tX, (int) tY).normalize();
Object[] res = world.calcMinDistanceAndObject3D(cam.getPosition(), dir, 10000);
if (res.length == 2) {
if (res[1] != null && res[1] instanceof Object3D) {
String name = ((Object3D) res[1]).getName();
tileChildRemoveQueue.add(name);
}
}


Here's the code that creates the tiles (and their possible children, but this will be removed soon when I can get this working):

public void generateHexagons() {
for (int y = 0; y < map.tiles[1].length; y++) {
for (int x = 0; x < map.tiles.length; x++) {
if (map.tiles[x][y].air)
continue;
map.tiles[x][y].height = (new Vec(x, y).distance(new Vec(map.tiles.length / 2, map.tiles[1].length / 2)) * 2) - 12;
Object3D cube;
cube = Models.get("hex");
cube.calcTextureWrap();
cube.setTexture("texture");
cube.setAdditionalColor(map.tiles[x][y].color);
cube.scale(1.025f);
cube.strip();
cube.build();
cube.translate((x * 15), map.tiles[x][y].height, -(17 * (2 * y + (x % 2)) / 2));
cube.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
cube.setName("Tile_" + x + ";" + y);

if (Math.random() > 0.95) {
Object3D child;
child = Models.get("smallhouse");
child.calcTextureWrap();
child.setTexture("texture");
child.setAdditionalColor(Math.random() > 0.5 ? new RGBColor(125, 125, 125) : new RGBColor(125, 75, 12));
child.scale(1.025f);
child.strip();
child.build();
child.translate((x * 15), map.tiles[x][y].height, -(17 * (2 * y + (x % 2)) / 2));
child.setName("Child_" + x + ";" + y);
map.tiles[x][y].child = child;
world.addObject(child);
}
map.tiles[x][y].hexagon = cube;
world.addObject(cube);
}
}
}


And here is my output:
10-05 09:07:37.910: I/System.out(26263): fail. x: 6 y: 1 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 7 y: 1 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 8 y: 1 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 9 y: 1 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 10 y: 1 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 4 y: 2 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 5 y: 2 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 6 y: 2 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 7 y: 2 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 8 y: 2 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 9 y: 2 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 10 y: 2 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 11 y: 2 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 12 y: 2 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 3 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 4 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 5 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 6 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 7 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 8 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 9 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 10 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 11 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 12 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 13 y: 3 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 2 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 3 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 4 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 5 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 6 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 7 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 8 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 9 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 10 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 11 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 12 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 13 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 14 y: 4 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 2 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 3 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 4 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 5 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 6 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 7 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 8 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 9 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 10 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 11 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 12 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 13 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 14 y: 5 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 1 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 2 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 3 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 4 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 5 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 6 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 7 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 8 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.910: I/System.out(26263): fail. x: 9 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 10 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 11 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 12 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 13 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 14 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 15 y: 6 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 1 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 2 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 3 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 4 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 5 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 6 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 7 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 8 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 9 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 10 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 11 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 12 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 13 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 14 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 15 y: 7 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 1 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 2 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 3 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 4 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 5 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 6 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 7 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 8 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 9 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 10 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 11 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 12 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 13 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 14 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 15 y: 8 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 1 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 2 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 3 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 4 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 5 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 6 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 7 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 8 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 9 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 10 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 11 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 12 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 13 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 14 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 15 y: 9 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 1 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 2 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 3 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 4 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 5 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 6 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 7 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 8 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 9 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 10 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 11 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 12 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 13 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 14 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 15 y: 10 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 2 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 3 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 4 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 5 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 6 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 7 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 8 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 9 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 10 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 11 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 12 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 13 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 14 y: 11 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 2 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 3 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.915: I/System.out(26263): fail. x: 4 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 5 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 6 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 7 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 8 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 9 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 10 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 11 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 12 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 13 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 14 y: 12 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 3 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 4 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 5 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 6 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 7 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 8 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 9 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 10 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 11 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 12 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 13 y: 13 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 4 y: 14 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 5 y: 14 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 6 y: 14 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 7 y: 14 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 8 y: 14 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 9 y: 14 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 10 y: 14 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 11 y: 14 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 12 y: 14 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 6 y: 15 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 7 y: 15 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 8 y: 15 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 9 y: 15 requested name: Tile_2;11 got name: Tile_10;15
10-05 09:07:37.920: I/System.out(26263): fail. x: 10 y: 15 requested name: Tile_2;11 got name: Tile_10;15


Apologies for the long(ish) post, just wanted to give you as much information as possible.
What am I doing wrong?

EgonOlsen

 ??? setName()/getName() are simple getters and setters for a String. I don't see why they should return the same name for all objects unless you assigned them that way (which i can't see in your code, it seems fine to me). I suggest to add some debug output when creating the objects (print out the names you assign and the names they all have after creation is done) as well as some simple debug output before working the queue to see if they still have the correct names.
If the name somehow changes, i suggest to create a subclass of Object3D for your queue and override setName with something like


public void setName(String n) {
     Logger.log("Name set to: "+n);
     Logger.log(new Exception(), Logger.WARNING);
     super.setName(n);
}


to see if something in the code fiddles around with the name.

Apart from all that, i don't recommend to implement the queue in that way anyway. I rather suggest to queue the x,y-location of the event and do the actual tile detection in the render thread as well. That's more thread safe (because by using Interact2D.reproject2D3DWS(cam, fb, (int) tX, (int) tY).normalize(); and world.calcMinDistanceAndObject3D(cam.getPosition(), dir, 10000); you are fiddling around with jPCT-AE instances in the event thread and you are not supposed to do that) and should be easier to implement as well.

LemonLake

After moving it all to the drawFrame and storing a Vec in the queue, I still get the same result. I made it print the tile name upon creation, and got this:


But when tapping, got this:


if (tileChildRemoveQueue.size() > 0) {
for (Vec p : tileChildRemoveQueue) {
String name;
SimpleVector dir = Interact2D.reproject2D3DWS(cam, fb, (int) p.x, (int) p.y).normalize();
Object[] res = world.calcMinDistanceAndObject3D(cam.getPosition(), dir, 10000);
if (res.length == 2) {
if (res[1] != null && res[1] instanceof Object3D) {
name = ((Object3D) res[1]).getName();
for (int y = 0; y < map.tiles[1].length; y++) {
for (int x = 0; x < map.tiles.length; x++) {
Tile tile = map.tiles[x][y];
if (tile.air) {
System.out.println("nope");
continue;
}
if (!tile.hexagon.getName().equalsIgnoreCase(name)) {
System.out.println("mismatch, " + tile.hexagon.getName() + " " + name);
continue;
}
if (tile.child != null) {
System.out.println("Removing child x: " + x + " y: " + y + " name: " + name + " tile name: " + tile.hexagon.getName());
world.removeObject(tile.child);
tile.child = null;
}
}
}
}
}
}
tileChildRemoveQueue.clear();
}


Never getting a "Removing child" print.

EgonOlsen

I would still try to override idea that i mentioned to see if something sets the name after creation. In addition, you might want to print out the object ID and maybe the instance itself to see if you actually are accessing different objects.

LemonLake

Quote from: EgonOlsen on October 05, 2013, 01:15:56 PM
I would still try to override idea that i mentioned to see if something sets the name after creation. In addition, you might want to print out the object ID and maybe the instance itself to see if you actually are accessing different objects.

I just tried that now, but I couldn't quite cast the 3DS loader to it.

EgonOlsen

No, you can't. But you can create a new instance out of the loaded one by using new Object3D(yourLoadedObj);

LemonLake

#10
As it turns out, Tile_10;15 is the last object to be created. However nothing seems to be changing it at runtime, so it appears to be a problem with the list(s). I'll try using world.getObjectByName().

Edit: Went back to the good old string reading method, however I'm back at the initial problem; it removes the first object it can find.

EgonOlsen

I don't think that getObjectByName() will change anything. Have you tried to not set the name at all? What's the output for that? And can you please post the complete log output?

LemonLake

#12
1. Not setting the name causes the application to crash due to the fact that the tile information is stored in it's name. I'll try doing a loop again, and after that I will post output.

2. http://pastebin.com/3Wu9htm8

EgonOlsen

That log is missing the good stuff, i.e. the log output that the engine produces...

LemonLake