Author Topic: NullPointerException when cloning Object3D  (Read 1590 times)

Offline Derkai

  • byte
  • *
  • Posts: 2
    • View Profile
NullPointerException when cloning Object3D
« on: March 05, 2011, 04:49:50 pm »
Hello all,

I have a little problem when cloning objects. I hope someone can help me, before I go crazy.  :-X

I create my base object:

Code: [Select]
float[] positions = ...
float[] uvs = ...
int[] indices = ...
_base = new Object3D(positions, uvs, indices, -1);
_base.strip();
_base.build(true);
_base.compile();

In my render/update loop i create a clone and add it to the world:

Code: [Select]
_clone1 = _base.cloneObject();
_clone1.shareCompiledData(_base);
_clone1.build();
_clone1.compile();
_world.addObject(_clone1);

Some frames later, I remove the first clone from the world:

Code: [Select]
_world.removeObject(_clone1);
The same frame I want to add another clone, wich gives me a NullPointerException:

Code: [Select]
_clone2 = _base.cloneObject(); // NullPointerException in GLSurfaceView$GLThread.run() line: 1120
_clone2.shareCompiledData(_base);
_clone2.build();
_clone2.compile();
_world.addObject(_clone2);


(Well there is a litte more code the this, but posting all would be to much for this one post. I hope this is enough.)

I tried everything now to find out why and how, but cant find any solution. What am I doing wrong or dont I understand here?

Offline Derkai

  • byte
  • *
  • Posts: 2
    • View Profile
Re: NullPointerException when cloning Object3D
« Reply #1 on: March 05, 2011, 05:44:11 pm »
Allright, I was going crazy to soon.

The answer is simple: Don't strip the base object. Removing _base.strip(); solved the problem.

P.S.: Thanks for jPCT-AE, makes life much easier... well, most of the time.  :P

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11971
    • View Profile
    • http://www.jpct.net
Re: NullPointerException when cloning Object3D
« Reply #2 on: March 05, 2011, 06:02:21 pm »
I'll look at it to see if i can add a warning or an error when cloning a stripped object.
« Last Edit: March 05, 2011, 08:06:36 pm by EgonOlsen »