catch ode4j error
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
d9e0b2a9e5
commit
2fbfaf4887
@ -273,48 +273,55 @@ public class CollisionEngine {
|
||||
!(bodyPointerMap.get(b1).getType() == Collidable.TYPE_TERRAIN && bodyPointerMap.get(b2).getType() == Collidable.TYPE_TERRAIN) &&
|
||||
!(bodyPointerMap.get(b1).getType() == Collidable.TYPE_FOLIAGE_STATIC && bodyPointerMap.get(b2).getType() == Collidable.TYPE_FOLIAGE_STATIC)
|
||||
){
|
||||
//calculate collisions
|
||||
int numc = OdeHelper.collide(o1,o2,MAX_CONTACTS,contacts.getGeomBuffer());
|
||||
//create DContacts based on each collision that occurs
|
||||
if (numc != 0) {
|
||||
DMatrix3 RI = new DMatrix3();
|
||||
RI.setIdentity ();
|
||||
for (int i=0; i<numc; i++) {
|
||||
DContact contact = contacts.get(i);
|
||||
//special code for ray casting
|
||||
if (o1 instanceof DRay || o2 instanceof DRay){
|
||||
DMatrix3 Rotation = new DMatrix3();
|
||||
Rotation.setIdentity();
|
||||
// dsDrawSphere(contact.geom.pos, Rotation, (0.01));
|
||||
try {
|
||||
//calculate collisions
|
||||
int numc = OdeHelper.collide(o1,o2,MAX_CONTACTS,contacts.getGeomBuffer());
|
||||
//create DContacts based on each collision that occurs
|
||||
if (numc != 0) {
|
||||
DMatrix3 RI = new DMatrix3();
|
||||
RI.setIdentity ();
|
||||
for (int i=0; i<numc; i++) {
|
||||
DContact contact = contacts.get(i);
|
||||
//special code for ray casting
|
||||
if (o1 instanceof DRay || o2 instanceof DRay){
|
||||
DMatrix3 Rotation = new DMatrix3();
|
||||
Rotation.setIdentity();
|
||||
// dsDrawSphere(contact.geom.pos, Rotation, (0.01));
|
||||
|
||||
DVector3 End = new DVector3();
|
||||
End.eqSum( contact.geom.pos, contact.geom.normal, contact.geom.depth );
|
||||
DVector3 End = new DVector3();
|
||||
End.eqSum( contact.geom.pos, contact.geom.normal, contact.geom.depth );
|
||||
|
||||
// dsDrawLine(contact.geom.pos, End);
|
||||
continue;
|
||||
// dsDrawLine(contact.geom.pos, End);
|
||||
continue;
|
||||
}
|
||||
// contact.geom.pos
|
||||
resolveCollision(
|
||||
bodyPointerMap.get(o1.getBody()),
|
||||
bodyPointerMap.get(o2.getBody()),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.geom.normal).mul(-1.0),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.fdir1).mul(-1.0),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.geom.pos),
|
||||
(float)contact.geom.depth
|
||||
);
|
||||
resolveCollision(
|
||||
bodyPointerMap.get(o2.getBody()),
|
||||
bodyPointerMap.get(o1.getBody()),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.geom.normal),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.fdir1),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.geom.pos),
|
||||
(float)contact.geom.depth
|
||||
);
|
||||
|
||||
//add contact to contact group
|
||||
DJoint c = OdeHelper.createContactJoint (world,contactgroup,contact );
|
||||
c.attach (b1,b2);
|
||||
}
|
||||
// contact.geom.pos
|
||||
resolveCollision(
|
||||
bodyPointerMap.get(o1.getBody()),
|
||||
bodyPointerMap.get(o2.getBody()),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.geom.normal).mul(-1.0),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.fdir1).mul(-1.0),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.geom.pos),
|
||||
(float)contact.geom.depth
|
||||
);
|
||||
resolveCollision(
|
||||
bodyPointerMap.get(o2.getBody()),
|
||||
bodyPointerMap.get(o1.getBody()),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.geom.normal),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.fdir1),
|
||||
PhysicsUtils.odeVecToJomlVec(contact.geom.pos),
|
||||
(float)contact.geom.depth
|
||||
);
|
||||
|
||||
//add contact to contact group
|
||||
DJoint c = OdeHelper.createContactJoint (world,contactgroup,contact );
|
||||
c.attach (b1,b2);
|
||||
}
|
||||
} catch(ArrayIndexOutOfBoundsException ex){
|
||||
//I've found that ode4j occasionally throws an exception on the OdeHelper.collide function.
|
||||
//I don't know why it has out of bounds elements, but it's happening.
|
||||
//Catching the exception here allows the engine to keep running at least.
|
||||
LoggerInterface.loggerEngine.ERROR("ode4j error", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user