Author Topic: Flickering when using world.removeObject ?  (Read 1345 times)

Offline sticksen

  • byte
  • *
  • Posts: 15
    • View Profile
Flickering when using world.removeObject ?
« on: October 05, 2011, 12:34:38 am »
Hi there,

When Im using world.removeObject, sometimes the screen flickers. Log shows repeatedly:

Code: [Select]
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 Im guessing its this NullPointerException that causes the flickering.

My relevant code:
Code: [Select]
//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);
}

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

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Flickering when using world.removeObject ?
« Reply #1 on: October 05, 2011, 02:33:22 am »
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.

Offline sticksen

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Flickering when using world.removeObject ?
« Reply #2 on: October 05, 2011, 03:43:25 am »
ok, that seems to be the problem. thank you!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11775
    • View Profile
    • http://www.jpct.net
Re: Flickering when using world.removeObject ?
« Reply #3 on: October 05, 2011, 06:52:08 am »
jPCT-AE (as well as jPCT) isn't thread safe: http://www.jpct.net/wiki/index.php/Multithreading#Thread_safety