catch ode4j error
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-04-21 22:20:35 -04:00
parent d9e0b2a9e5
commit 2fbfaf4887

View File

@ -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_TERRAIN && bodyPointerMap.get(b2).getType() == Collidable.TYPE_TERRAIN) &&
!(bodyPointerMap.get(b1).getType() == Collidable.TYPE_FOLIAGE_STATIC && bodyPointerMap.get(b2).getType() == Collidable.TYPE_FOLIAGE_STATIC) !(bodyPointerMap.get(b1).getType() == Collidable.TYPE_FOLIAGE_STATIC && bodyPointerMap.get(b2).getType() == Collidable.TYPE_FOLIAGE_STATIC)
){ ){
//calculate collisions try {
int numc = OdeHelper.collide(o1,o2,MAX_CONTACTS,contacts.getGeomBuffer()); //calculate collisions
//create DContacts based on each collision that occurs int numc = OdeHelper.collide(o1,o2,MAX_CONTACTS,contacts.getGeomBuffer());
if (numc != 0) { //create DContacts based on each collision that occurs
DMatrix3 RI = new DMatrix3(); if (numc != 0) {
RI.setIdentity (); DMatrix3 RI = new DMatrix3();
for (int i=0; i<numc; i++) { RI.setIdentity ();
DContact contact = contacts.get(i); for (int i=0; i<numc; i++) {
//special code for ray casting DContact contact = contacts.get(i);
if (o1 instanceof DRay || o2 instanceof DRay){ //special code for ray casting
DMatrix3 Rotation = new DMatrix3(); if (o1 instanceof DRay || o2 instanceof DRay){
Rotation.setIdentity(); DMatrix3 Rotation = new DMatrix3();
// dsDrawSphere(contact.geom.pos, Rotation, (0.01)); Rotation.setIdentity();
// dsDrawSphere(contact.geom.pos, Rotation, (0.01));
DVector3 End = new DVector3(); DVector3 End = new DVector3();
End.eqSum( contact.geom.pos, contact.geom.normal, contact.geom.depth ); End.eqSum( contact.geom.pos, contact.geom.normal, contact.geom.depth );
// dsDrawLine(contact.geom.pos, End); // dsDrawLine(contact.geom.pos, End);
continue; 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);
} }
} }
} }