Skip to content

Commit

Permalink
fix: loading spine module on OPPO using separate engine (#15536)
Browse files Browse the repository at this point in the history
* fix: loading spine module on OPPO using separate engine
  • Loading branch information
PPpro authored Jun 26, 2023
1 parent bd28997 commit 1090830
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion pal/wasm/wasm-minigame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,30 @@
THE SOFTWARE.
*/

import { OPPO } from 'internal:constants';

export function instantiateWasm (wasmUrl: string, importObject: WebAssembly.Imports): Promise<any> {
wasmUrl = `cocos-js/${wasmUrl}`;
return WebAssembly.instantiate(wasmUrl, importObject);
}

export function fetchBuffer (binaryUrl: string): Promise<ArrayBuffer> {
return new Promise<ArrayBuffer>((resolve, reject) => {
globalThis.fsUtils.readArrayBuffer(`cocos-js/${binaryUrl}`, (err, arrayBuffer) => {
// fsUtils is defined in engine-adapter
const fsUtils = globalThis.fsUtils;
if (OPPO) {
getBinaryUrlOnOPPO(binaryUrl).then((url) => {
fsUtils.readArrayBuffer(url, (err, arrayBuffer) => {
if (err) {
reject(err);
return;
}
resolve(arrayBuffer);
});
}).catch((e) => {});
return;
}
fsUtils.readArrayBuffer(`cocos-js/${binaryUrl}`, (err, arrayBuffer) => {
if (err) {
reject(err);
return;
Expand All @@ -38,3 +54,18 @@ export function fetchBuffer (binaryUrl: string): Promise<ArrayBuffer> {
});
});
}

// On OPPO platform, we put binary assets in cocos-library directory when using separate engine.
function getBinaryUrlOnOPPO (binaryUrl: string): Promise<string> {
return new Promise((resolve) => {
const urlInCocosJS = `cocos-js/${binaryUrl}`;
// fsUtils is defined in engine-adapter
globalThis.fsUtils.exists(urlInCocosJS, (isExists: boolean) => {
if (isExists) {
resolve(urlInCocosJS);
} else {
resolve(`cocos-library/${binaryUrl}`);
}
});
});
}

0 comments on commit 1090830

Please sign in to comment.