Explorar o código

Do not attach a disabled feature, allow null

Raanan Weber %!s(int64=5) %!d(string=hai) anos
pai
achega
c5bcfe095f

+ 11 - 1
src/XR/features/WebXRAbstractFeature.ts

@@ -16,6 +16,11 @@ export abstract class WebXRAbstractFeature implements IWebXRFeature {
     }[] = [];
     }[] = [];
 
 
     /**
     /**
+     * Is this feature disposed?
+     */
+    public isDisposed: boolean = false;
+
+    /**
      * Should auto-attach be disabled?
      * Should auto-attach be disabled?
      */
      */
     public disableAutoAttach: boolean = false;
     public disableAutoAttach: boolean = false;
@@ -23,7 +28,7 @@ export abstract class WebXRAbstractFeature implements IWebXRFeature {
     /**
     /**
      * The name of the native xr feature name (like anchor, hit-test, or hand-tracking)
      * The name of the native xr feature name (like anchor, hit-test, or hand-tracking)
      */
      */
-    public xrNativeFeatureName: string = '';
+    public xrNativeFeatureName: string = "";
 
 
     /**
     /**
      * Construct a new (abstract) WebXR feature
      * Construct a new (abstract) WebXR feature
@@ -45,6 +50,10 @@ export abstract class WebXRAbstractFeature implements IWebXRFeature {
      * @returns true if successful, false is failed or already attached
      * @returns true if successful, false is failed or already attached
      */
      */
     public attach(force?: boolean): boolean {
     public attach(force?: boolean): boolean {
+        // do not attach a disposed feature
+        if (this.isDisposed) {
+            return false;
+        }
         if (!force) {
         if (!force) {
             if (this.attached) {
             if (this.attached) {
                 return false;
                 return false;
@@ -83,6 +92,7 @@ export abstract class WebXRAbstractFeature implements IWebXRFeature {
      */
      */
     public dispose(): void {
     public dispose(): void {
         this.detach();
         this.detach();
+        this.isDisposed = true;
     }
     }
 
 
     /**
     /**

+ 3 - 3
src/XR/features/WebXRControllerTeleportation.ts

@@ -140,7 +140,7 @@ export class WebXRMotionControllerTeleportation extends WebXRAbstractFeature {
     private _currentTeleportationControllerId: string;
     private _currentTeleportationControllerId: string;
     private _floorMeshes: AbstractMesh[];
     private _floorMeshes: AbstractMesh[];
     private _quadraticBezierCurve: AbstractMesh;
     private _quadraticBezierCurve: AbstractMesh;
-    private _selectionFeature: IWebXRFeature;
+    private _selectionFeature: Nullable<IWebXRFeature>;
     private _snapToPositions: Vector3[];
     private _snapToPositions: Vector3[];
     private _snappedToPoint: boolean = false;
     private _snappedToPoint: boolean = false;
     private _teleportationRingMaterial?: StandardMaterial;
     private _teleportationRingMaterial?: StandardMaterial;
@@ -330,8 +330,8 @@ export class WebXRMotionControllerTeleportation extends WebXRAbstractFeature {
      * This is used to remove the selection rays when moving.
      * This is used to remove the selection rays when moving.
      * @param selectionFeature the feature to disable when forward movement is enabled
      * @param selectionFeature the feature to disable when forward movement is enabled
      */
      */
-    public setSelectionFeature(selectionFeature: IWebXRFeature) {
-        this._selectionFeature = selectionFeature;
+    public setSelectionFeature(selectionFeature?: IWebXRFeature) {
+        this._selectionFeature = selectionFeature || null;
     }
     }
 
 
     protected _onXRFrame(_xrFrame: XRFrame) {
     protected _onXRFrame(_xrFrame: XRFrame) {