瀏覽代碼

Merge pull request #9777 from kaliatech/fix-chrome-passive-evt-warning

Fix passive event warning in chrome
David Catuhe 4 年之前
父節點
當前提交
69764629e4
共有 2 個文件被更改,包括 23 次插入1 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 22 1
      src/Inputs/scene.inputManager.ts

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

@@ -104,6 +104,7 @@
 - Fix SSAO2 with PrePass sometimes causing colors brighter than they should be ([CraigFeldspar](https://github.com/CraigFeldspar))
 - Fix PostProcess sharing between cameras/renderTargets, that would create/destroy a texture on every frame ([CraigFeldspar](https://github.com/CraigFeldspar))
 - Fix for DualSense gamepads being incorrectly read as DualShock gamepads ([PolygonalSun](https://github.com/PolygonalSun))
+- Fix for warning in chrome about passive wheel events ([#9777](https://github.com/BabylonJS/Babylon.js/pull/9777)) ([kaliatech](https://github.com/kaliatech))
 - Fix crash when cloning material in `AssetContainer.instantiateModelsToScene` when mesh is an instanced mesh ([Popov72](https://github.com/Popov72))
 
 ## Breaking changes

+ 22 - 1
src/Inputs/scene.inputManager.ts

@@ -848,7 +848,28 @@ export class InputManager {
                     ? "mousewheel" // Webkit and IE support at least "mousewheel"
                     : "DOMMouseScroll"; // let's assume that remaining browsers are older Firefox
 
-            elementToAttachTo.addEventListener(this._wheelEventName, <any>this._onPointerMove, false);
+            // Chrome reports warning in console if wheel listener doesn't set an explicit passive option.
+            // IE11 only supports captureEvent:boolean, not options:object, and it defaults to false.
+            // Feature detection technique copied from: https://github.com/github/eventlistener-polyfill (MIT license)
+            // ----------
+            var passiveSupported = false;
+            var noop = function () {};
+            try {
+                var options: object = {
+                        passive: {
+                            get: function () {
+                                passiveSupported = true;
+                            }
+                        }
+                    };
+                elementToAttachTo.addEventListener("test", noop, options);
+                elementToAttachTo.removeEventListener("test", noop, options);
+            } catch (e) {
+                /* */
+            }
+            // ----------
+
+            elementToAttachTo.addEventListener(this._wheelEventName, <any>this._onPointerMove, passiveSupported ? { passive: false } : false);
         }
 
         if (attachDown) {