jPCT-AE - a 3d engine for Android > Support

project crash when remove Object3D from world JPCT AE

(1/3) > >>

viniciusDSL:
Hello, I start with this engine JPCT AE and I try to make a game similar to guitar hero, but i have a problem when try to remove Object3D from world, this is my code:


--- Code: ---public void onSurfaceChanged(GL10 gl, int w, int h) {
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(gl, w, h);

if (master == null) {


texture = new Texture(BitmapHelper.rescale(
BitmapHelper.convert(getResources().getDrawable(
R.drawable.ic_launcher)), 64, 64));
TextureManager.getInstance().addTexture("texture", texture);

cube = Primitives.getCube(2);
cube.calcTextureWrapSpherical();
cube.setTexture("texture");


cube1 = Primitives.getCube(2);
cube1.calcTextureWrapSpherical();
cube1.setTexture("texture");


cube2 = Primitives.getCube(2);
cube2.calcTextureWrapSpherical();
cube2.setTexture("texture");

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(new SimpleVector(0, 0, 0));

MemoryHelper.compact();

if (master == null) {
Logger.log("Saving master Activity!");
master = BrokenStrings.this;
}
}
}

public void onDrawFrame(GL10 gl) {

if (h.mTicksElapsed + 500 >= midiFile.getTick()) {
Object3D clon1 = null;
switch ((((NoteOn) midiFile).getNoteValue() % 12) % 3) {
case 0:
                                        //Create clon and add to world and LinkedList
clon1 = cube.cloneObject();
clon1.build();
clon1.setOrigin(new SimpleVector(0, -30, 10));
world.addObject(clon1);
clon1.rotateX(-10);
notes.add(clon1);
break;

case 1:
                                        //Create clon and add to world and LinkedList
clon1 = cube1.cloneObject();
clon1.build();
clon1.setOrigin(new SimpleVector(0, -30, 10));
world.addObject(clon1);
clon1.rotateX(-10);
notes.add(clon1);
break;

case 2:
                                        //Create clon and add to world and LinkedList
clon1 = cube2.cloneObject();
clon1.build();
clon1.setOrigin(new SimpleVector(0, -30, 10));
world.addObject(clon1);
clon1.rotateX(-10);
notes.add(clon1);
break;
}
midiFile = midi.nextOn();
}
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();
notes2.addAll(notes);
Iterator<Object3D> i = notes2.iterator();
Object3D _it;
while (i.hasNext()) {
_it = i.next();
_it.translate(0, 0.4f, -0.3f);
if (_it.getCenter().y > -10f) {
removeNote(_it, i);
                                        //i try to remove when the object is not visible in the smartphone
world.removeObject(_it);
}
}
notes2.addAll(notes);
notes.clear();
}
}
 



--- End code ---

when run i have this:

10-08 11:17:53.557: E/AndroidRuntime(3188): FATAL EXCEPTION: main
10-08 11:17:53.557: E/AndroidRuntime(3188): java.lang.RuntimeException: [ 1349709473570 ] - ERROR: Can't remove object #3, because it doesn't belong to this World!
10-08 11:17:53.557: E/AndroidRuntime(3188):    at com.threed.jpct.Logger.log(Logger.java:189)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at com.threed.jpct.World.removeObject(World.java:267)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at com.binizzio.brokenstringsv1.BrokenStrings$3.run(BrokenStrings.java:402)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at android.os.Handler.handleCallback(Handler.java:587)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at android.os.Looper.loop(Looper.java:130)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at android.app.ActivityThread.main(ActivityThread.java:3835)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at java.lang.reflect.Method.invokeNative(Native Method)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at java.lang.reflect.Method.invoke(Method.java:507)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
10-08 11:17:53.557: E/AndroidRuntime(3188):    at dalvik.system.NativeStart.main(Native Method)

Thanks for the help and best regards.
PD: sorry my english is bad

EgonOlsen:
The exception says


--- Quote ---Can't remove object #3, because it doesn't belong to this World!
--- End quote ---

...so you are removing something from a world that isn't a part of it. Just stop doing that... ;) Apart from that, make sure that you removing and adding objects either at startup only or in the rendering thread. Don't do it in listener callbacks from touch or other events.

viniciusDSL:
Hello, thanks for reply, now know little of this engine, i want remove Object3D when this is not visible in the smartphone, but do not know the methods that run each second  :-\ , where I can find them?

PD:sorry for my english

EgonOlsen:
I don't get the question...which "method that run each second" do you mean?

viniciusDSL:
sorry, method that is running all the time in the application, how onDrawFrame()

Navigation

[0] Message Index

[#] Next page

Go to full version