Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong asm.js mem url on minigame platforms #15559

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 22 additions & 33 deletions pal/wasm/wasm-minigame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
THE SOFTWARE.
*/

import { OPPO } from 'internal:constants';
import { XIAOMI } from 'internal:constants';

export function instantiateWasm (wasmUrl: string, importObject: WebAssembly.Imports): Promise<any> {
wasmUrl = `cocos-js/${wasmUrl}`;
Expand All @@ -31,41 +31,30 @@ export function instantiateWasm (wasmUrl: string, importObject: WebAssembly.Impo

export function fetchBuffer (binaryUrl: string): Promise<ArrayBuffer> {
return new Promise<ArrayBuffer>((resolve, reject) => {
// 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;
}
Comment on lines -34 to -47
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I revert this bug fix because we cannot rely on the file read interface on production enviroment, the engine plugin is not in the package.

I fix this url issue in the editor build plugin instead https://github.com/cocos/creator-runtime-extensions/pull/443/commits/cfb00bf2996d7ab44ce3a43a3fbd80cc99a450e2

fsUtils.readArrayBuffer(`cocos-js/${binaryUrl}`, (err, arrayBuffer) => {
if (err) {
reject(err);
return;
}
resolve(arrayBuffer);
});
getPlatformBinaryUrl(binaryUrl).then((url) => {
// NOTE: fsUtils is defined in engine-adapter, we need to access globalThis explicitly for Taobao platform
globalThis.fsUtils.readArrayBuffer(url, (err, arrayBuffer) => {
if (err) {
reject(err);
return;
}
resolve(arrayBuffer);
});
}).catch((e) => {});
});
}

// On OPPO platform, we put binary assets in cocos-library directory when using separate engine.
function getBinaryUrlOnOPPO (binaryUrl: string): Promise<string> {
/**
* The binary url can be different on different platforms.
* @param binaryUrl the basic build output binary url
* @returns the real binary url on the exact platform
*/
function getPlatformBinaryUrl (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}`);
}
});
if (XIAOMI) {
resolve(`src/cocos-js/${binaryUrl}`);
} else {
resolve(`cocos-js/${binaryUrl}`);
}
});
}