Przeglądaj źródła

Fix crash when creating audio engine in web worker

Popov72 4 lat temu
rodzic
commit
7ff6dd11d0
1 zmienionych plików z 4 dodań i 0 usunięć
  1. 4 0
      src/Audio/audioEngine.ts

+ 4 - 0
src/Audio/audioEngine.ts

@@ -5,6 +5,7 @@ import { Observable } from "../Misc/observable";
 import { Logger } from "../Misc/logger";
 import { Engine } from "../Engines/engine";
 import { IAudioEngine } from './Interfaces/IAudioEngine';
+import { DomManagement } from "../Misc/domManagement";
 
 // Sets the default audio engine to Babylon.js
 Engine.AudioEngineFactory = (hostElement: Nullable<HTMLElement>) => { return new AudioEngine(hostElement); };
@@ -94,6 +95,9 @@ export class AudioEngine implements IAudioEngine {
      * @param hostElement defines the host element where to display the mute icon if necessary
      */
     constructor(hostElement: Nullable<HTMLElement> = null) {
+        if (!DomManagement.IsWindowObjectExist()) {
+            return;
+        }
         if (typeof window.AudioContext !== 'undefined' || typeof window.webkitAudioContext !== 'undefined') {
             window.AudioContext = window.AudioContext || window.webkitAudioContext;
             this.canUseWebAudio = true;