From dde7961a7196a694330ef1b5dcf4e1e717a94aac Mon Sep 17 00:00:00 2001 From: Fabio Arnold Date: Wed, 12 Oct 2022 15:37:30 +0200 Subject: [PATCH] WebAudio: check if `window` is defined before accessing it In certain environments (WebWorkers for instance) `window` is undefined. Accessing it will lead to an `Uncaught ReferenceError` that can't be handled by the calling C code. That's why I added a check that will return 0 in such case. --- miniaudio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 1d80625f..1deb03b4 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -38952,7 +38952,7 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex /* Here is where our global JavaScript object is initialized. */ resultFromJS = EM_ASM_INT({ - if ((window.AudioContext || window.webkitAudioContext) === undefined) { + if (typeof window === 'undefined' || (window.AudioContext || window.webkitAudioContext) === undefined) { return 0; /* Web Audio not supported. */ }