File tree Expand file tree Collapse file tree 8 files changed +55
-12
lines changed
MixedRealityToolkit.SDK/Features/UX/Scripts/Pointers
MixedRealityToolkit.Services/InputSystem Expand file tree Collapse file tree 8 files changed +55
-12
lines changed Original file line number Diff line number Diff line change @@ -139,14 +139,34 @@ protected override async void Start()
139139 {
140140 base . Start ( ) ;
141141
142- if ( lateRegisterTeleport )
142+ if ( lateRegisterTeleport && MixedRealityToolkit . Instance . ActiveProfile . IsTeleportSystemEnabled )
143143 {
144- await new WaitUntil ( ( ) => MixedRealityToolkit . TeleportSystem != null ) ;
144+ if ( MixedRealityToolkit . TeleportSystem == null )
145+ {
146+ await new WaitUntil ( ( ) => MixedRealityToolkit . TeleportSystem != null ) ;
147+
148+ // We've been destroyed during the await.
149+ if ( this == null )
150+ {
151+ return ;
152+ }
153+ }
154+
145155 lateRegisterTeleport = false ;
146156 MixedRealityToolkit . TeleportSystem . Register ( gameObject ) ;
147157 }
148158
149- await WaitUntilInputSystemValid ;
159+ if ( MixedRealityToolkit . InputSystem == null )
160+ {
161+ await WaitUntilInputSystemValid ;
162+ }
163+
164+ // We've been destroyed during the await.
165+ if ( this == null )
166+ {
167+ return ;
168+ }
169+
150170 SetCursor ( ) ;
151171 }
152172
Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ public override void OnPreRaycast()
150150 for ( int i = 0 ; i < Rays . Length ; i ++ )
151151 {
152152 Vector3 currentPoint = lineBase . GetUnClampedPoint ( stepSize * ( i + 1 ) ) ;
153- Rays [ i ] = new RayStep ( lastPoint , currentPoint ) ;
153+ Rays [ i ] . UpdateRayStep ( ref lastPoint , ref currentPoint ) ;
154154 lastPoint = currentPoint ;
155155 }
156156 }
Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ public override void OnPreRaycast()
146146 for ( int i = 0 ; i < Rays . Length ; i ++ )
147147 {
148148 Vector3 currentPoint = LineBase . GetUnClampedPoint ( stepSize * ( i + 1 ) ) ;
149- Rays [ i ] = new RayStep ( lastPoint , currentPoint ) ;
149+ Rays [ i ] . UpdateRayStep ( ref lastPoint , ref currentPoint ) ;
150150 lastPoint = currentPoint ;
151151 }
152152
Original file line number Diff line number Diff line change @@ -252,9 +252,12 @@ public void UpdateFocusLockedHit()
252252 pointerWasLocked = true ;
253253 }
254254
255- // In case the focused object is moving, we need to update the focus point based on the object's new transform.
256- focusDetails . Point = focusDetails . Object . transform . TransformPoint ( pointLocalSpace ) ;
257- focusDetails . Normal = focusDetails . Object . transform . TransformDirection ( normalLocalSpace ) ;
255+ if ( focusDetails . Object != null && focusDetails . Object . transform != null )
256+ {
257+ // In case the focused object is moving, we need to update the focus point based on the object's new transform.
258+ focusDetails . Point = focusDetails . Object . transform . TransformPoint ( pointLocalSpace ) ;
259+ focusDetails . Normal = focusDetails . Object . transform . TransformDirection ( normalLocalSpace ) ;
260+ }
258261
259262 StartPoint = Pointer . Rays [ 0 ] . Origin ;
260263
Original file line number Diff line number Diff line change @@ -199,7 +199,8 @@ public override void OnPreRaycast()
199199 newGazeNormal = stabilizer . StableRay . direction ;
200200 }
201201
202- Rays [ 0 ] . UpdateRayStep ( newGazeOrigin , newGazeOrigin + ( newGazeNormal * pointerExtent ) ) ;
202+ Vector3 endPoint = newGazeOrigin + ( newGazeNormal * pointerExtent ) ;
203+ Rays [ 0 ] . UpdateRayStep ( ref newGazeOrigin , ref endPoint ) ;
203204
204205 gazeProvider . HitPosition = Rays [ 0 ] . Origin + ( gazeProvider . lastHitDistance * Rays [ 0 ] . Direction ) ;
205206 }
Original file line number Diff line number Diff line change @@ -28,7 +28,17 @@ protected virtual async void Start()
2828 {
2929 if ( lateInitialize )
3030 {
31- await WaitUntilInputSystemValid ;
31+ if ( MixedRealityToolkit . InputSystem == null )
32+ {
33+ await WaitUntilInputSystemValid ;
34+ }
35+
36+ if ( this == null )
37+ {
38+ // We've been destroyed during the await.
39+ return ;
40+ }
41+
3242 lateInitialize = false ;
3343 MixedRealityToolkit . InputSystem . Register ( gameObject ) ;
3444 }
Original file line number Diff line number Diff line change @@ -31,7 +31,13 @@ public Vector3 GetPoint(float distance)
3131 return Vector3 . MoveTowards ( Origin , Terminus , distance ) ;
3232 }
3333
34- public void UpdateRayStep ( Vector3 origin , Vector3 terminus )
34+ /// <summary>
35+ /// Update current raystep with new origin and terminus points.
36+ /// Pass by ref to avoid unnecessary struct copy into function since values will be copied anyways locally
37+ /// </summary>
38+ /// <param name="origin">beginning of raystep origin</param>
39+ /// <param name="terminus">end of raystep</param>
40+ public void UpdateRayStep ( ref Vector3 origin , ref Vector3 terminus )
3541 {
3642 Origin = origin ;
3743 Terminus = terminus ;
Original file line number Diff line number Diff line change @@ -66,7 +66,10 @@ public static Camera Main
6666 /// <param name="newMain">New main camera to cache</param>
6767 public static Camera Refresh ( Camera newMain )
6868 {
69- Debug . Assert ( newMain != null , "No camera with MainCamera tag found in scene. Did you forget to tag your camera?" ) ;
69+ if ( newMain == null )
70+ {
71+ Debug . LogWarning ( "A null camera was passed into CameraCache.Refresh()" ) ;
72+ }
7073 return cachedCamera = newMain ;
7174 }
7275 }
You can’t perform that action at this time.
0 commit comments