add some logs, fix frontend memory leak with users not deallocating their haku

closes #28
This commit is contained in:
りき萌 2024-08-22 20:49:24 +02:00
parent 6c88a041ea
commit 4ebd150e59
3 changed files with 28 additions and 5 deletions

View file

@ -130,6 +130,11 @@ export class Haku {
w.haku_limits_destroy(pLimits);
}
destroy() {
w.haku_brush_destroy(this.#pBrush);
w.haku_instance_destroy(this.#pInstance);
}
setBrush(code) {
w.haku_reset(this.#pInstance);
// NOTE: Brush is invalid at this point, because we reset removes all defs and registered chunks.

View file

@ -15,6 +15,10 @@ export class User {
this.painter = new Painter(wallInfo.paintArea);
}
destroy() {
this.haku.destroy();
}
setBrush(brush) {
let compileResult = this.haku.setBrush(brush);
this.isBrushOk = compileResult.status == "ok";
@ -57,6 +61,7 @@ export class OnlineUsers extends EventTarget {
removeUser(sessionId) {
if (this.#users.has(sessionId)) {
let user = this.#users.get(sessionId);
user.destroy();
console.info("user removed", sessionId, user.nickname);
// TODO: Cleanup reticles
this.#users.delete(sessionId);