microsoft / MixedReality-WorldLockingTools-Unity

Unity tools to provide a stable coordinate system anchored to the physical world.
https://microsoft.github.io/MixedReality-WorldLockingTools-Unity/README.html
MIT License
188 stars 45 forks source link

Minor index error in SpacePinBinder AddSpacePin #277

Closed genereddick closed 2 years ago

genereddick commented 2 years ago

In the code in SpacePinBinder file, when you attempt to add a pin at runtime it will re-add the first item in the index:

public bool AddSpacePin(SpacePinQrAsa spacePin)
{
    // mafish - make sure it's not already in there.
    int idx = FindSpacePin(spacePin);
    if (idx <= 0)
    {
        SpacePins.Add(spacePin);

But, in FindSpacePin, the first item in the list returns an index of 0

/// <returns>Index in the list if found, else -1.</returns>

Which falls through the if statement and then gets added again to the list

if (idx <= 0)

I think this should just be <, rather than <=:

if (idx < 0)
fast-slow-still commented 2 years ago

@genereddick, yes, you're right, that's a type-o, and if (idx <= 0) should be if (idx < 0).

Thanks for reporting it!

fast-slow-still commented 2 years ago

Fixed with #279

Also fixed in the sibling Samples repo: https://github.com/microsoft/MixedReality-WorldLockingTools-Samples/pull/83

Many thanks again for pointing this out!