vivominigame / issues

vivo小游戏问题反馈和统一回复入口
13 stars 9 forks source link

WebAssembly支持问题 #213

Open shuizhongyueming opened 4 years ago

shuizhongyueming commented 4 years ago

相关信息

问题描述

希望基于WebAssembly来进行小游戏开发,但是WebAssembly.compile()调用之后返回的Promise一直没有响应。

核心的代码如下:

var instance = module_factory();

var loadFile;

if (window.qg) {
    var fs = window.qg.getFileSystemManager();
     loadFile = new Promise(function(resolve, reject) {
        fs.readFile({
            uri: "demo.wasm",
            encoding: "binary",
            success: res => resolve(res.text),
            fail: () => reject()
        });
     });
} else {
      loadFile = fetch('./demo.wasm').then(res => res.arrayBuffer())
}

var wasm_instance = loadFile
    .then(function (bytes) {
        console.log('load demo.wasm success', bytes);
        const compileRes = WebAssembly.compile(bytes);
        console.log('WebAssembly.compile res: ', compileRes);
        return  compileRes;
    })
    .catch(e => {
        console.log('compile failed with error: ', e);
    })
    .then(function (mod) {
        console.log('compile demo.wasm success');
        const res = WebAssembly.instantiate(mod, instance.imports);
        console.log('WebAssembly.instantiate res: ', res);
        return res;
    })
    .catch(e => {
        console.log('instantiate failed with error: ', e);
    });

return wasm_instance
    .then( function( wasm_instance ) {
        var exports = instance.initialize( wasm_instance );
        console.log( "Finished loading Rust wasm module 'demo'" );
        return exports;
    })
    .catch( function( error ) {
        console.log( "Error loading Rust wasm module 'demo':", error );
        throw error;
    });

在调试模式下,在devtools里面可以看到的日志只有:

load demo.wasm success ArrayBuffer(51225)
WebAssembly.compile res:  Promise

compile的promise,一直没有resolve,也没有reject

复现步骤

这个demo项目是修改自一个微信小游戏支持wasm的demo: https://github.com/planet0104/miniprogram-rust-wasm.git

这个rpk文件是我的demo: https://cowtransfer.com/s/98210145d63e46

jesseband commented 4 years ago

1.7.7.700 会实现对于WebAssembly的支持 近期会全量 可以关注下

shuizhongyueming commented 4 years ago

期待,全量之后的最低引擎版本需要更新吗

JiJiWang commented 3 years ago

平台版本1.9.2.501,还是不支持WebAssembly,WebAssembly.instantiate的promise还是没返回,请问已经支持了吗 @jesseband

yuebai008 commented 1 year ago

不要使用调试模式 ,直接将rpk导入手机内打开试下 wasm在调试状态可能会出现无法返回的情况

yuebai008 commented 1 year ago

目前调试模式下 Unity引擎也可以正常加载,需要使用该引擎去测试 https://vassets.vvstc.com/vassets/og2pg/o/com.vivo.hybrid_v1.10.2.250_3775967fb_202211242028.apk