Author Topic: world.removeObject(Object3D) crash  (Read 2181 times)

Offline LemonLake

  • byte
  • *
  • Posts: 13
    • View Profile
world.removeObject(Object3D) crash
« on: October 04, 2013, 08:24:22 pm »
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:
Code: [Select]
    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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: world.removeObject(Object3D) crash
« Reply #1 on: October 04, 2013, 08:51:14 pm »
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

Offline LemonLake

  • byte
  • *
  • Posts: 13
    • View Profile
Re: world.removeObject(Object3D) crash
« Reply #2 on: October 04, 2013, 08:54:48 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: world.removeObject(Object3D) crash
« Reply #3 on: October 04, 2013, 10:12:39 pm »
Yes, something like that.

Offline LemonLake

  • byte
  • *
  • Posts: 13
    • View Profile
Re: world.removeObject(Object3D) crash
« Reply #4 on: October 05, 2013, 10:13:38 am »
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:
Code: [Select]
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:
Code: [Select]
                                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):

Code: [Select]
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:
Code: [Select]
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?
« Last Edit: October 05, 2013, 10:15:28 am by LemonLake »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: world.removeObject(Object3D) crash
« Reply #5 on: October 05, 2013, 11:37:56 am »
 ??? 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

Code: [Select]
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.

Offline LemonLake

  • byte
  • *
  • Posts: 13
    • View Profile
Re: world.removeObject(Object3D) crash
« Reply #6 on: October 05, 2013, 01:06:22 pm »
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:


Code: [Select]
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: world.removeObject(Object3D) crash
« Reply #7 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.

Offline LemonLake

  • byte
  • *
  • Posts: 13
    • View Profile
Re: world.removeObject(Object3D) crash
« Reply #8 on: October 05, 2013, 01:16:23 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: world.removeObject(Object3D) crash
« Reply #9 on: October 05, 2013, 01:19:45 pm »
No, you can't. But you can create a new instance out of the loaded one by using new Object3D(yourLoadedObj);

Offline LemonLake

  • byte
  • *
  • Posts: 13
    • View Profile
Re: world.removeObject(Object3D) crash
« Reply #10 on: October 05, 2013, 01:24:38 pm »
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.
« Last Edit: October 05, 2013, 01:33:59 pm by LemonLake »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: world.removeObject(Object3D) crash
« Reply #11 on: October 05, 2013, 01:46:38 pm »
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?

Offline LemonLake

  • byte
  • *
  • Posts: 13
    • View Profile
Re: world.removeObject(Object3D) crash
« Reply #12 on: October 05, 2013, 01:50:24 pm »
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
« Last Edit: October 05, 2013, 01:54:18 pm by LemonLake »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: world.removeObject(Object3D) crash
« Reply #13 on: October 05, 2013, 02:00:53 pm »
That log is missing the good stuff, i.e. the log output that the engine produces...

Offline LemonLake

  • byte
  • *
  • Posts: 13
    • View Profile
Re: world.removeObject(Object3D) crash
« Reply #14 on: October 05, 2013, 02:21:49 pm »
That log is missing the good stuff, i.e. the log output that the engine produces...

http://pastebin.com/EdgqhUxw