Skip to content

Commit

Permalink
Wrapping contact/separation callbacks in try/catch to avoid freezes
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipAlg committed Nov 17, 2023
1 parent 3437f84 commit a2f962d
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions AGXUnity/ContactEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,12 @@ private void TriggerSeparationCallbacks()
separationData.Component2 = GetComponent( g2 );
separationData.Geometry1 = g1;
separationData.Geometry2 = g2;
listener.SeparationCallback( separationData );
try {
listener.SeparationCallback( separationData );
}
catch ( System.Exception e ) {
Debug.LogException( e );
}
g1.ReturnToPool();
g2.ReturnToPool();
sep.ReturnToPool();
Expand Down Expand Up @@ -534,25 +539,31 @@ private void GenerateDataAndExecuteCallbacks( bool hasForce )
break;

ref var contactData = ref GeometryContactHandler.ContactData[ (int)contactIndex ];
var hasModifications = listener.ContactCallback( ref contactData );

// Ignoring synchronization of any modifications when we are
// in post, when the changes won't have any effect.
if ( hasForce || !hasModifications )
continue;
try {
bool hasModifications = listener.ContactCallback( ref contactData );

var gc = GeometryContactHandler.Native.getGeometryContact( contactIndex );
// Ignoring synchronization of any modifications when we are
// in post, when the changes won't have any effect.
if ( hasForce || !hasModifications )
continue;

gc.setEnable( contactData.Enabled );
var gc = GeometryContactHandler.Native.getGeometryContact( contactIndex );

var gcPoints = gc.points();
for ( int pointIndex = 0; pointIndex < contactData.Points.Count; ++pointIndex ) {
var gcPoint = gcPoints.at( (uint)pointIndex );
contactData.Points[ pointIndex ].Synchronize( gcPoint );
gcPoint.ReturnToPool();
gc.setEnable( contactData.Enabled );

var gcPoints = gc.points();
for ( int pointIndex = 0; pointIndex < contactData.Points.Count; ++pointIndex ) {
var gcPoint = gcPoints.at( (uint)pointIndex );
contactData.Points[ pointIndex ].Synchronize( gcPoint );
gcPoint.ReturnToPool();
}
gcPoints.ReturnToPool();
gc.ReturnToPool();
}
catch ( System.Exception e ) {
Debug.LogException( e );
}
gcPoints.ReturnToPool();
gc.ReturnToPool();
}
}
OnEndPerformingCallbacks();
Expand Down

0 comments on commit a2f962d

Please sign in to comment.