Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange
#20
(10-08-2022, 08:55 AM)josemendez Wrote: This means the particle indices you're passing to the distance constraints are incorrect, and the distance constraints are accessing non-existent particles.

Obi does not perform out of bounds checks at runtime, as that would be too expensive. In particular, the Oni backend does not perform any kind of checks, so out of bounds accesses result in undefined behavior (may crash, may cause heap corruption, all bets are off). The Burst backend relies on Unity's own safety system/debugger that will help you identify these issues, as happened here.

Upon further inspection, I see the particle indices you're passing to AttachParticlePairInColon() are hardcoded via the component's inspector. Since these values are all in the 900-1000 range, I'm guessing they're either vertex indices or actor indices, which seems to be incorrect since you're passing them to solver batches (unless I misunderstood something in your code). If they're were hardcoded solver indices, it wouldn't work either, because solver indices are not guaranteed to be the same across multiple executions of the scene so you cannot hardcode them.

When an actor gets added to a solver, a new index in the solver arrays for each actor particle is assigned. These indices (solver indices) can be different depending on the order in which actors get added, which is undefined (since the order in which Unity calls Awake(), Start() and other events for different objects is undefined):


So it may work correctly, it may not work at all, it may result in completely different parts of your actors being sewn together.

There's an additional problem if you intend for these constraints to be persistent: as soon as you add a new actor to the solver, all constraints you've manually added to the solver will disappear, replaced with the ones in the actor's blueprints. Remember that adding a new actor to a solver calls SetConstraintsDirty(), and this triggers a replacement of all actor constraints with the ones stored in the blueprints.

All things considered, it looks like what you actually want is to add these constraints to the blueprints, not to the solver, because these constraints are not ephemeral but must be enforced over the entire object's lifetime. Will write an example for you asap.

Thanks for the reply. You are correct that I hard-coded some vertex indices for the process. However, you can see that my method is looking up for the solver index for the particle that is closest to each of the vertex, then passing the particle indices to the AddConstraint().

Plus if my method is getting out of bound error, it doesn't make sense that you didn't encounter the same error on your side.

Is it possible to send a copy of the script modified by you?
Reply


Messages In This Thread
RE: Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange - by snowtv - 10-08-2022, 07:35 PM