-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4d07bb
commit 67afa84
Showing
2 changed files
with
45 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import init, * as wasm_bindgen from './src.js'; | ||
|
||
function jsInit() { | ||
console.log("Wasm module initialized"); | ||
|
||
if (typeof window.resize_callback === 'undefined' && typeof wasm_bindgen.resize_callback !== 'undefined') { | ||
console.log("Setting resize callback"); | ||
window.resize_callback = wasm_bindgen.resize_callback; | ||
} | ||
|
||
const canvas = document.getElementById('canvas'); | ||
|
||
function resizeCanvas() { | ||
const canvas = document.getElementById('canvas'); | ||
const width = window.innerWidth; | ||
const height = window.innerHeight; | ||
canvas.width = width; | ||
canvas.height = height; | ||
|
||
if (typeof window.resize_callback === 'function') { | ||
window.resize_callback(width, height); | ||
} | ||
} | ||
|
||
window.addEventListener('resize', resizeCanvas); | ||
window.addEventListener('load', resizeCanvas); | ||
} | ||
init().then(() => { | ||
jsInit(); | ||
}).catch(err => { | ||
if (err.message.includes("Using exceptions for control flow")) { | ||
console.warn("Ignoring expected Wasm initialization exception and proceeding."); | ||
try { | ||
jsInit(); | ||
} catch (err) { | ||
console.error("Error in continuing initialisation:", err); | ||
throw err; | ||
} | ||
} else { | ||
console.error("Error initializing wasm module:", err); | ||
throw err; | ||
} | ||
}); | ||
console.log("Wasm module initialization call made"); |