Author Topic: Collision exception  (Read 1327 times)

Offline mbartnic

  • byte
  • *
  • Posts: 3
    • View Profile
Collision exception
« on: January 09, 2012, 11:16:25 pm »
Hello,

I have encountered following problem:

Durring execution of this line:

Code: [Select]
model.checkForCollisionEllipsoid(sv, new SimpleVector(.5f, 1.0f, 0.5f), 3);
Sometimes exception is thrown:

Code: [Select]
01-09 23:10:49.590: E/AndroidRuntime(12805): FATAL EXCEPTION: Thread-11
01-09 23:10:49.590: E/AndroidRuntime(12805): java.lang.RuntimeException: [ 1326147049599 ] - ERROR: java.lang.NullPointerException
01-09 23:10:49.590: E/AndroidRuntime(12805): at com.threed.jpct.Object3D.getWorldTransformation(Object3D.java:2531)
01-09 23:10:49.590: E/AndroidRuntime(12805): at com.threed.jpct.Object3D.getInverseWorldTransformation(Object3D.java:6494)
01-09 23:10:49.590: E/AndroidRuntime(12805): at com.threed.jpct.Object3D.ellipsoidIntersectsAABB(Object3D.java:3633)
01-09 23:10:49.590: E/AndroidRuntime(12805): at com.threed.jpct.World.doWorldCollisionEllipsoid(World.java:1933)
01-09 23:10:49.590: E/AndroidRuntime(12805): at com.threed.jpct.World.doWorldCollisionEllipsoid(World.java:2046)
01-09 23:10:49.590: E/AndroidRuntime(12805): at com.threed.jpct.World.doWorldCollisionEllipsoid(World.java:2046)
01-09 23:10:49.590: E/AndroidRuntime(12805): at com.threed.jpct.World.checkSomeCollisionEllipsoid(World.java:1797)
01-09 23:10:49.590: E/AndroidRuntime(12805): at com.threed.jpct.World.checkObjCollisionEllipsoid(World.java:1287)
01-09 23:10:49.590: E/AndroidRuntime(12805): at com.threed.jpct.Object3D.checkForCollisionEllipsoid(Object3D.java:2697)

I do not know what could be wrong - I try to catch it but the app crushes.

Any clues why does it happen?

Object is added already to the game world.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Collision exception
« Reply #1 on: January 09, 2012, 11:36:41 pm »
Which version of jPCT-AE is that? Maybe rotation or translation matrix of that object is null?

Offline mbartnic

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Collision exception
« Reply #2 on: January 10, 2012, 01:06:05 am »
Newest jPCT-ae release and you are right transformation matrix is null, but I don't know why. I do just translation and rotation in Y axis and ofcourse collision detection. Does it matter if I have logic and display in different  threads?

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Collision exception
« Reply #3 on: January 10, 2012, 02:05:17 am »
Yes it matters. If you are modifying 3D objects while jPCT is drawing it can cause exceptions.

You should update the object movement and rotation in the same thread from within the onDrawFrame(GL10 gl) function. Use a frame delta (time elapsed since the previous frame) to move/rotate your objects, for example: translationVector.x += fSpeed * fDelta;

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Collision exception
« Reply #4 on: January 10, 2012, 09:33:04 am »
Some words on thread safety (apply to jPCT-AE too): http://www.jpct.net/wiki/index.php/Multithreading#Thread_safety

Offline mbartnic

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Collision exception
« Reply #5 on: January 10, 2012, 08:28:19 pm »
Thank you for answers, they helped a lot.