Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange
#18
(09-08-2022, 08:53 PM)snowtv Wrote: Thanks for the instructions!

I disabled the compilation and here is the error message:


Code:
IndexOutOfRangeException: Index 0 is out of range of '0' Length.
Unity.Collections.NativeArray`1[T].FailOutOfRangeError (System.Int32 index) (at <2e6610ed29844f85a37924f81509fe5d>:0)
Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at <2e6610ed29844f85a37924f81509fe5d>:0)
Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at <2e6610ed29844f85a37924f81509fe5d>:0)
Obi.BurstDistanceConstraintsBatch+DistanceConstraintsBatchJob.Execute (System.Int32 i) (at Assets/Obi/Scripts/Common/Backends/Burst/Constraints/Distance/BurstDistanceConstraintsBatch.cs:101)
Unity.Jobs.IJobParallelForExtensions+ParallelForJobStruct`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <2e6610ed29844f85a37924f81509fe5d>:0)
Unity.Jobs.JobHandle:ScheduleBatchedJobsAndComplete(JobHandle&)
Unity.Jobs.JobHandle:Complete()
Obi.BurstJobHandle:Complete() (at Assets/Obi/Scripts/Common/Backends/Burst/BurstJobHandle.cs:20)
Obi.ObiUpdater:Substep(Single, Single, Int32) (at Assets/Obi/Scripts/Common/Updaters/ObiUpdater.cs:78)
Obi.ObiFixedUpdater:FixedUpdate() (at Assets/Obi/Scripts/Common/Updaters/ObiFixedUpdater.cs:50)

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):

Quote:You cannot specify the order in which an event function is called for different instances of the same MonoBehaviour subclass. For example, the Update function of one MonoBehaviour might be called before or after the Update function for the same MonoBehaviour on another GameObject — including its own parent or child GameObjects.

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.
Reply


Messages In This Thread
RE: Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange - by josemendez - 10-08-2022, 08:55 AM