19-06-2018, 10:50 AM
Thanks for the quick reply. I understand that I mixed up the constraint indices with the particle indices. However even after adjusting the code to remove the right index, the access violation error still triggers at random.
The weird thing is that when I try to trigger the access violation by feeding the pinconstraints non existing indices, the access violation crash is not triggered!
The current code is:
Is there still something wrong with this?
And above all, why is it that the whole application crashes by inserting a wrong index according to you?
Cant this be fixed by throwing a safe exception? An access violation crash seems a bit harsh for an out of bounds exception!
I hope you can help me resolve this issue.
The new dump file of the crash that is still occurring: https://we.tl/SoBARZU6P0
The weird thing is that when I try to trigger the access violation by feeding the pinconstraints non existing indices, the access violation crash is not triggered!
The current code is:
Code:
public override T Spawn<T>(WorldObject worldObject)
{
T genericSpawnedObject = base.Spawn<T>(worldObject);
HitablePulleyWorldObject spawnedObject = genericSpawnedObject as HitablePulleyWorldObject;
if (spawnedObject != null)
{
ObiPinConstraintBatch batch = PinConstraints.GetFirstBatch();
if (batch != null)
{
PinConstraints.RemoveFromSolver(null);
int index = GetClosestParticleIndex();
if (index >= 0)
{
batch.AddConstraint(index, spawnedObject.GetComponentInChildren<ObiCollider>(), Vector3.zero, 1);
spawnedObject.ConstraintIndex = batch.ConstraintCount - 1;
spawnedObject.PinConstraints = PinConstraints;
}
PinConstraints.AddToSolver(null);
}
}
return genericSpawnedObject;
}
private int GetClosestParticleIndex()
{
int result = -1;
float closestDistance = float.MaxValue;
for (int i = 0; i < Rope.invMasses.Length; i++)
{
if (Rope.invMasses[i] > 0)
{
float distance = Vector3.Distance(Rope.GetParticlePosition(i), transform.position);
if (distance < closestDistance)
{
closestDistance = distance;
result = i;
}
}
}
return result;
}
Code:
private void DetachFromRope()
{
ObiPinConstraintBatch batch = PinConstraints.GetFirstBatch();
if (batch != null && ConstraintIndex < batch.ConstraintCount)
{
PinConstraints.RemoveFromSolver(null);
batch.RemoveConstraint(ConstraintIndex);
PinConstraints.AddToSolver(null);
}
Object.Destroy(GetComponent<ObiCollider>());
}
Is there still something wrong with this?
And above all, why is it that the whole application crashes by inserting a wrong index according to you?
Cant this be fixed by throwing a safe exception? An access violation crash seems a bit harsh for an out of bounds exception!
I hope you can help me resolve this issue.
The new dump file of the crash that is still occurring: https://we.tl/SoBARZU6P0