Skip to content

Commit

Permalink
Fix null ref in SpatialManipulationReticle when multiple interactable…
Browse files Browse the repository at this point in the history
…s are hovered (#873)

* Check that the hovered interactable is an ISnapInteractable

* Update SpatialManipulationReticle.cs

* Update CHANGELOG.md

---------

Co-authored-by: Adam Mollis <[email protected]>
  • Loading branch information
keveleigh and AMollis authored Jul 25, 2024
1 parent 70bba0a commit 0e027dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the BSD 3-Clause

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;

Expand All @@ -19,7 +20,6 @@ public class SpatialManipulationReticle : MonoBehaviour, IReticleVisual
[field: SerializeField, Tooltip("The type of the reticle visuals. Scale or Rotate.")]
public SpatialManipulationReticleType ReticleType { get; set; }

private Transform contextTransform;
private Quaternion worldRotationCache;

/// <summary>
Expand Down Expand Up @@ -47,7 +47,23 @@ public void UpdateVisual(ReticleVisualUpdateArgs args)
}
else if (rayInteractor.interactablesHovered.Count > 0)
{
RotateReticle(args.ReticleNormal, rayInteractor.interactablesHovered[0].transform);
int interactableIndex = 0;

List<IXRHoverInteractable> hoveredInteractables = rayInteractor.interactablesHovered;
int hoveredCount = hoveredInteractables.Count;
if (hoveredCount > 1)
{
for (int i = 0; i < hoveredCount; i++)
{
if (hoveredInteractables[i] is BoundsHandleInteractable)
{
interactableIndex = i;
break;
}
}
}

RotateReticle(args.ReticleNormal, hoveredInteractables[interactableIndex].transform);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions org.mixedrealitytoolkit.spatialmanipulation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Fixed

* Fixed tap to place `StartPlacement()` when called just after instantiation of the component. [PR #785](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/785)
* Fix null ref in SpatialManipulationReticle when multiple interactables are hovered. [PR #873](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/873)

## [3.3.0-development] - 2024-04-30
## [3.3.0] - 2024-04-30

### Added

Expand All @@ -18,7 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

* Added null check and index check when hiding colliders on BoundsHandleInteractable. [PR #730](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/730)

## [3.2.0-development] - 2024-03-20
## [3.2.0] - 2024-03-20

### Added

Expand Down

0 comments on commit 0e027dd

Please sign in to comment.