med-material / vrtactility

🤏 Exploring electro-tactile stimulation in Virtual Reality
Apache License 2.0
1 stars 1 forks source link

Grabbing the ball with two hands results in ArgumentOutOfRangeException #14

Closed kuff closed 1 year ago

kuff commented 1 year ago

This issue has nothing to do with the tactility implementation, and was observed before work began on it.

If the grabbable object (sphere) is being touched by both the left and right hands (not necessarily grabbing it but just simply touching) the internal state logic of the UniformGrabbable component becomes permanently desynchronized, resulting in an index-out-of-bounds exception on every frame:

image

This also means that pressure will not be calculated after this error occurs until the app is completely restarted.

More specifically, this issue is caused by a loss of maintained state synchronization between the _touchingBoneCapsules List and _touchingBonePressures Array, meaning some objects are removed from one array without their counterpart being removed from the other. Below are lines 61 to 62 of the UniformGrabbable script, where applied pressures are calculated for each physics capsule (finger bone):

for (var i = 0; i < _touchingBoneCapsules.Count; i++)
      touchingBonePressures[i] = GetAppliedPressure(_touchingBoneCapsules[i]);

The indexing variable i cannot possibly be less than zero, which means that when the desynchronization happens, the _touchingBoneCapsules List must have become larger than the _touchingBonePressures Array, leading to indexing with a value that is equal to the size of the Array, which is illegal. This means that either items are removed prematurely from _touchingBonePressures or not removed in time from _touchingBoneCapsules.

kuff commented 1 year ago

Fixed as of https://github.com/med-material/vrtactility/commit/4854854718cbe6c68900a14f0502511cb6c0536b.