Flickering when using world.removeObject ?

Started by sticksen, October 05, 2011, 12:34:38 AM

Previous topic - Next topic

sticksen

Hi there,

When I´m using world.removeObject, sometimes the screen flickers. Log shows repeatedly:

10-05 00:22:32.890: INFO/jPCT-AE(23039): Loading Texture...
10-05 00:22:33.060: INFO/jPCT-AE(23039): OpenGL vendor:     NVIDIA Corporation
10-05 00:22:33.060: INFO/jPCT-AE(23039): OpenGL renderer:   NVIDIA AP
10-05 00:22:33.060: INFO/jPCT-AE(23039): OpenGL version:    OpenGL ES-CM 1.1
10-05 00:22:33.060: INFO/jPCT-AE(23039): OpenGL renderer initialized (using 2 texture stages)
10-05 00:22:33.060: INFO/jPCT-AE(23039): Subobject of object 2/0 compiled to flat fixed point data using 24 vertices in 0ms!
10-05 00:22:33.060: INFO/jPCT-AE(23039): Static references cleared...
10-05 00:22:33.060: INFO/jPCT-AE(23039): Object 2/0 compiled to 1 subobjects in 1ms!
10-05 00:22:33.100: INFO/jPCT-AE(23039): 0fps
10-05 00:22:33.170: INFO/jPCT-AE(23039): Static references cleared...
10-05 00:22:33.180: INFO/jPCT-AE(23039): Subobject of object 6/1 compiled to flat fixed point data using 6 vertices in 0ms!
10-05 00:22:33.180: INFO/jPCT-AE(23039): Object 6/1 compiled to 1 subobjects in 2ms!
10-05 00:22:33.270: INFO/jPCT-AE(23039): Static references cleared...
10-05 00:22:33.270: INFO/jPCT-AE(23039): java.lang.NullPointerException
10-05 00:22:33.270: INFO/jPCT-AE(23039):     at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2015)
10-05 00:22:33.270: INFO/jPCT-AE(23039):     at com.threed.jpct.World.draw(World.java:1355)
10-05 00:22:33.270: INFO/jPCT-AE(23039):     at com.threed.jpct.World.draw(World.java:1136)
10-05 00:22:33.270: INFO/jPCT-AE(23039):     at myPackage.gl.MapRenderer.onDrawFrame(MapRenderer.java:186)
10-05 00:22:33.270: INFO/jPCT-AE(23039):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1429)
10-05 00:22:33.270: INFO/jPCT-AE(23039):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1184)


So I´m guessing it´s this NullPointerException that causes the flickering.

My relevant code:

//this is triggered by some external source...maybe every 100ms
Object3D traj3D = trajectory.generateObject3D();
traj3D.setName("" + trajectory.getId());
traj3D.build();
Object3D lookup = world.getObjectByName("" + trajectory.getId());
world.addObject(traj3D);
rootNode.addChild(traj3D);
//TODO this is flickering
if (lookup != null) {
    world.removeObject(lookup);
    rootNode.removeChild(lookup);
}


@Override
    public void onDrawFrame(GL10 gl) {
// Log.v(TAG, "onDrawFrame");

try {
    if (!stop) {

fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();

if (System.currentTimeMillis() - time >= 1000) {
    Logger.log(fps + "fps");
    fps = 0;
    time = System.currentTimeMillis();
}
fps++;
    } else {
if (fb != null) {
    fb.dispose();
    fb = null;
}
    }
} catch (Exception e) {
    Logger.log(e, Logger.MESSAGE);
}
    }

Any guess what it could be? Any chance to get the relevant jpct code lines?

Cheers, Marc

K24A3

Try to add and remove objects in the main rendering thread (within onDrawFrame) rather than a different thread such as onTouch events/listeners.
If you remove objects at the same time jPCT is rendering the scene, you can cause null pointer exceptions and other problems.

sticksen