Skip to content

Commit

Permalink
Revert "fix: add WASM_FALLBACK for spine wasm module (#15511)"
Browse files Browse the repository at this point in the history
This reverts commit e5dde7f.
  • Loading branch information
dumganhar committed Jun 21, 2023
1 parent 6b9b6a2 commit 386c5a2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
6 changes: 0 additions & 6 deletions cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,6 @@
"type": "boolean",
"value": false,
"internal": true
},
"WASM_FALLBACK": {
"comment": "An internal constant to indicate whether need a fallback of wasm.\nIf true, we build a wasm fallback module for the compatibility of wasm files compiled by different version of emscripten.\nThis is useful when we use wasm on different version of Safari browsers.",
"type": "boolean",
"value": "$HTML5",
"internal": true
}
},

Expand Down
34 changes: 1 addition & 33 deletions cocos/spine/lib/instantiated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*/

import { instantiateWasm, fetchBuffer } from 'pal/wasm';
import { systemInfo } from 'pal/system-info';
import { JSB, WASM_SUPPORT_MODE, CULL_ASM_JS_MODULE, WASM_FALLBACK, HTML5 } from 'internal:constants';
import { JSB, WASM_SUPPORT_MODE, CULL_ASM_JS_MODULE } from 'internal:constants';
import asmFactory from 'external:emscripten/spine/spine.asm.js';
import asmJsMemUrl from 'external:emscripten/spine/spine.js.mem';
import wasmFactory from 'external:emscripten/spine/spine.wasm.js';
Expand All @@ -33,7 +32,6 @@ import { game } from '../../game';
import { getError, error, sys } from '../../core';
import { WebAssemblySupportMode } from '../../misc/webassembly-support';
import { overrideSpineDefine } from './spine-define';
import { BrowserType } from '../../../pal/system-info/enum-type';

const PAGESIZE = 65536; // 64KiB

Expand All @@ -50,36 +48,6 @@ const registerList: any[] = [];
function initWasm (wasmUrl): Promise<void> {
return new Promise<void>((resolve, reject) => {
const errorMessage = (err: any): string => `[Spine]: Spine wasm load failed: ${err}`;
if (WASM_FALLBACK) {
if (HTML5 && systemInfo.isMobile && systemInfo.browserType === BrowserType.SAFARI) {
const safariVersion = /Version\/([\d.]+)/.exec(window.navigator.userAgent)?.[1];
if (safariVersion && Number.parseInt(safariVersion.split('.')[0]) < 15) {
// NOTE: we need to fallback to the wasm which is compiled by lower version of emscripten.
Promise.all([
import('external:emscripten/spine/spine.wasm.fallback'),
import('external:emscripten/spine/spine.wasm.fallback.js')]).then(([
{ default: wasmFallbackUrl },
{ default: wasmFallbackFactory },
]) => {
wasmFallbackFactory({
instantiateWasm (importObject: WebAssembly.Imports,
receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void) {
// NOTE: the Promise return by instantiateWasm hook can't be caught.
instantiateWasm(wasmFallbackUrl, importObject).then((result: any) => {
receiveInstance(result.instance, result.module);
}).catch((err) => reject(errorMessage(err)));
},
}).then((Instance: any) => {
wasmInstance = Instance;
registerList.forEach((cb) => {
cb(wasmInstance);
});
}).then(resolve).catch((err: any) => reject(errorMessage(err)));
}).catch(reject);
return;
}
}
}
wasmFactory({
instantiateWasm (importObject: WebAssembly.Imports,
receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void) {
Expand Down

0 comments on commit 386c5a2

Please sign in to comment.