Skip to content

Commit ef5379f

Browse files
committed
feat(wasm): define locateFile and onRuntimeInitialized only when
1 parent 60a92c4 commit ef5379f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/wasmLoader.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,25 @@ function isSameConfig(a, b) {
3636
}
3737

3838
export function generateWasmConfig(config) {
39-
return {
40-
locateFile: (fileName) => {
39+
if (WASM_FILE_OBJECT) {
40+
config.locateFile = (fileName) => {
4141
if (WASM_FILE_OBJECT && fileName == WASM_FILE_OBJECT.name) {
4242
return URL.createObjectURL(WASM_FILE_OBJECT);
4343
}
4444
return new URL(fileName, import.meta.url).href;
45-
},
46-
onRuntimeInitialized: (module) => {
47-
if (WASM_FILE_OBJECT) {
48-
URL.revokeObjectURL(WASM_FILE_OBJECT);
49-
}
50-
},
51-
preRun: config?.rendering === "webgpu" ? [(module) => {
45+
};
46+
config.onRuntimeInitialized = () => {
47+
// Free the object URL after runtime is initialized
48+
URL.revokeObjectURL(WASM_FILE_OBJECT);
49+
WASM_FILE_OBJECT = null;
50+
};
51+
}
52+
if (config?.rendering === "webgpu") {
53+
config.preRun = [(module) => {
5254
module.ENV.VTK_GRAPHICS_BACKEND = "WEBGPU";
53-
}] : [],
55+
}];
5456
}
57+
return config;
5558
}
5659

5760
/**

0 commit comments

Comments
 (0)