Skip to content

Commit 0d2b609

Browse files
Merge pull request #78 from white-axe/thread2
Threaded core fixes part 2
2 parents ef7bc1f + 9ede644 commit 0d2b609

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/classes/emulator.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,16 @@ export class Emulator {
245245
resize({ height, width }: { height: number; width: number }) {
246246
const { Module } = this.getEmscripten()
247247
if (typeof width === 'number' && typeof height === 'number') {
248-
Module.setCanvasSize(width, height)
248+
try {
249+
Module.setCanvasSize(width, height)
250+
} catch (error) {
251+
if (error instanceof DOMException) {
252+
Module.canvas.setAttribute('width', width.toString())
253+
Module.canvas.setAttribute('height', height.toString())
254+
} else {
255+
throw error
256+
}
257+
}
249258
}
250259
}
251260

src/libs/utils.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,28 @@ async function patchCoreJs({ js, name }: { js: ResolvableFile; name: string }) {
9696
}
9797
}`
9898
} else if (isEsmScript(jsContent)) {
99-
jsContent = `${jsContent.replace('var setImmediate', '').replace(
100-
'readyPromiseResolve(Module)',
101-
`readyPromiseResolve({
102-
AL: typeof AL === 'undefined' ? null: AL,
103-
Browser: typeof Browser === 'undefined' ? null: Browser,
104-
JSEvents,
105-
Module,
106-
exit: _emscripten_force_exit
107-
})`,
108-
)};
99+
jsContent = `${jsContent
100+
.replace('var setImmediate', '')
101+
.replace(
102+
'readyPromiseResolve(Module)',
103+
`readyPromiseResolve({
104+
AL: typeof AL === 'undefined' ? null: AL,
105+
Browser: typeof Browser === 'undefined' ? null: Browser,
106+
JSEvents,
107+
Module,
108+
exit: _emscripten_force_exit
109+
})`,
110+
)
111+
.replace(
112+
'return moduleRtn;',
113+
`return moduleRtn.then((Module) => ({
114+
AL: typeof AL === 'undefined' ? null: AL,
115+
Browser: typeof Browser === 'undefined' ? null: Browser,
116+
JSEvents,
117+
exit: _emscripten_force_exit,
118+
...Module,
119+
}));`,
120+
)};
109121
export function getEmscripten({ Module }) {
110122
const fnA = (typeof libretro_${name} === "function") ? libretro_${name} : null;
111123
const fnB = (typeof ${name} === "function") ? ${name} : null;

0 commit comments

Comments
 (0)