fix wasm path passing

This commit is contained in:
Fam Zheng 2025-10-15 12:44:40 +01:00
parent c08d830127
commit 80f72d0a7f
6 changed files with 22 additions and 13 deletions

View File

@ -8,8 +8,11 @@ var performance = {
Module['instantiateWasm'] = (info, receiveInstance) => {
console.log("loading wasm...", info);
// Use provided wasmPath parameter, fallback to hardcoded path
var wasmPath = Module.wasmFilePath || "pages/emblemscanner/qrtool.wx.wasm.br";
// Use global wasmFilePath (should always be set by the main app)
var wasmPath = global.wasmFilePath;
if (!wasmPath) {
throw new Error("wasmFilePath must be provided via global.wasmFilePath");
}
console.log("Using WASM path:", wasmPath);
WebAssembly.instantiate(wasmPath, info).then((result) => {

View File

@ -164,6 +164,7 @@ function get_current_package_path() {
*/
function get_wasm_file_path(filename) {
const packagePath = get_current_package_path();
console.log('current package path', packagePath);
return `${packagePath}/${filename}`;
}

View File

@ -8,12 +8,12 @@ var qrtool_ready = false;
* Load qrtool WASM module
*/
function load_qrtool(wasmFilePath) {
// Set global WASM file path before loading the module
global.wasmFilePath = wasmFilePath;
// Load the WASM module
var m = require('./qrtool.wx.js');
// Set the WASM file path
m.wasmFilePath = wasmFilePath;
m.onRuntimeInitialized = () => {
qrtool_ready = true;
qrtool = m;

View File

@ -34,8 +34,11 @@ var performance = {
};
Module["instantiateWasm"] = (info, receiveInstance) => {
console.log("loading wasm...", info);
// Use provided wasmPath parameter, fallback to hardcoded path
var wasmPath = Module.wasmFilePath || "pages/emblemscanner/qrtool.wx.wasm.br";
// Use global wasmFilePath (should always be set by the main app)
var wasmPath = global.wasmFilePath;
if (!wasmPath) {
throw new Error("wasmFilePath must be provided via global.wasmFilePath");
}
console.log("Using WASM path:", wasmPath);
WebAssembly.instantiate(wasmPath, info).then(result => {
console.log("result:", result);

View File

@ -1,11 +1,10 @@
console.log("hello from emblemscanner worker");
// Set WASM file path before loading qrtool
// Set global WASM file path before loading qrtool
// The wasmFilePath will be passed from the main thread when the worker is created
if (typeof worker !== "undefined" && worker.wasmFilePath) {
let qrtoolModule = require('./qrtool.wx.js');
qrtoolModule.wasmFilePath = worker.wasmFilePath;
let qrtool = qrtoolModule;
global.wasmFilePath = worker.wasmFilePath;
let qrtool = require('./qrtool.wx.js');
} else {
let qrtool = require('./qrtool.wx.js');
}

View File

@ -34,8 +34,11 @@ var performance = {
};
Module["instantiateWasm"] = (info, receiveInstance) => {
console.log("loading wasm...", info);
// Use provided wasmPath parameter, fallback to hardcoded path
var wasmPath = Module.wasmFilePath || "pages/emblemscanner/qrtool.wx.wasm.br";
// Use global wasmFilePath (should always be set by the main app)
var wasmPath = global.wasmFilePath;
if (!wasmPath) {
throw new Error("wasmFilePath must be provided via global.wasmFilePath");
}
console.log("Using WASM path:", wasmPath);
WebAssembly.instantiate(wasmPath, info).then(result => {
console.log("result:", result);