Browse Source

Remove Nullable<Number> from DeviceSourceManager.getInput, add observable cleanup to dispose() (#8833)

* This PR finalizes changes to the deviceSourceManager contract by removing Nulable<number> from `DeviceSourceManager.getInput`, this also improves the cleanup of DeviceSourceManager by properly cleaning up observables on `dispose()`"

* what's new

* Add additional fix to `deviceSourceManager.getDeviceSources` that only returns non-null entries

* Update what's new with bugfix

* Linting fixes
Nicholas Barlow 5 năm trước cách đây
mục cha
commit
e1c0f3822c

+ 2 - 0
dist/preview release/what's new.md

@@ -45,6 +45,7 @@
 - Photo Dome and Video Dome now use the same abstract class and support the same parameters ([#8771](https://github.com/BabylonJS/Babylon.js/issues/8771)) ([RaananW](https://github.com/RaananW))
 - Added `getTransformNodesByTags` support to `Scene` class ([MackeyK24](https://github.com/MackeyK24))
 - Added support for multi-pointer mesh selection and pointer over/out triggers ([#8820](https://github.com/BabylonJS/Babylon.js/issues/8820)) ([RaananW](https://github.com/RaananW))
+- Changed DeviceSourceManager getInput contract to no longer return nullable values for reals this time. Also added proper cleanup for DeviceSourceManager observables ([Drigax](https://github.com/drigax))
 
 ### Engine
 
@@ -296,6 +297,7 @@
 - Fixed issue with Babylon scene export of loaded glTF meshes.([Drigax]/(https://github.com/drigax))
 - Fixed an issue with text block wrap and unicode strings (not working in IE11) ([#8822](https://github.com/BabylonJS/Babylon.js/issues/8822)) ([RaananW](https://github.com/RaananW))
 - Fixed an issue with compound initialization that has rotation ([#8744](https://github.com/BabylonJS/Babylon.js/issues/8744)) ([RaananW](https://github.com/RaananW))
+- Fixed an issue in `DeviceSourceManager.getDeviceSources()` where null devices are returned ([Drigax](https://github.com/drigax))
 
 ## Breaking changes
 - `FollowCamera.target` was renamed to `FollowCamera.meshTarget` to not be in conflict with `TargetCamera.target` ([Deltakosh](https://github.com/deltakosh))

+ 6 - 2
src/DeviceInput/InputDevices/deviceSourceManager.ts

@@ -38,7 +38,7 @@ export class DeviceSource<T extends DeviceType> {
      * @param inputIndex index of specific input on device
      * @returns Input value from DeviceInputSystem
      */
-    public getInput(inputIndex: DeviceInput<T>): Nullable<number> {
+    public getInput(inputIndex: DeviceInput<T>): number {
         return this._deviceInputSystem.pollInput(this.deviceType, this.deviceSlot, inputIndex);
     }
 }
@@ -130,13 +130,17 @@ export class DeviceSourceManager implements IDisposable {
      * @returns Array of DeviceSource objects
      */
     public getDeviceSources<T extends DeviceType>(deviceType: T): ReadonlyArray<DeviceSource<T>> {
-        return this._devices[deviceType];
+        return this._devices[deviceType].filter((source) => { return !!source; });
     }
 
     /**
      * Dispose of DeviceInputSystem and other parts
      */
     public dispose() {
+        this.onBeforeDeviceConnectedObservable.clear();
+        this.onBeforeDeviceDisconnectedObservable.clear();
+        this.onAfterDeviceConnectedObservable.clear();
+        this.onAfterDeviceDisconnectedObservable.clear();
         this._deviceInputSystem.dispose();
     }