Skip to content

Commit 8a9103c

Browse files
Handle memory usage correctly
1 parent 620446e commit 8a9103c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

public/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ async function rendreSortie() {
324324
const h = entierSecurise(srcCanvas.height, 0, 1);
325325
const pixelData = srcCanvas.getContext("2d").getImageData(0, 0, w, h).data;
326326

327+
if (typeof wasm.__ml_reset === "function") wasm.__ml_reset();
328+
327329
outCanvas.width = w;
328330
outCanvas.height = h;
329331
const ctx = outCanvas.getContext("2d");

tests/smoke.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,29 @@ async function testAllTileCategoriesRenderWithWasm() {
498498
}
499499
}
500500

501+
async function testMlResetCalledBeforeEachRender() {
502+
const { elements, api } = buildHarness();
503+
const sourceCanvas = elements.get("source-canvas");
504+
sourceCanvas.width = 10;
505+
sourceCanvas.height = 10;
506+
let resetCount = 0;
507+
508+
api.setWasm({
509+
__ml_reset() { resetCount += 1; },
510+
couleur_moyenne(total, count) { return Math.round(total / count); },
511+
km_init() {}, km_ajouter() {}, km_calculer() {},
512+
km_r() { return 0; }, km_g() { return 0; }, km_b() { return 0; },
513+
generer_tuiles() { return 1; },
514+
tuile_n_sommets() { return 4; },
515+
tuile_sommet_x(_i, j) { return [0, 10, 10, 0][j]; },
516+
tuile_sommet_y(_i, j) { return [0, 0, 10, 10][j]; },
517+
});
518+
519+
await api.rendreSortie();
520+
await api.rendreSortie();
521+
assert.strictEqual(resetCount, 2, "expected __ml_reset called once per render");
522+
}
523+
501524
function testKMeansSamplingStaysUnderWasmLimit() {
502525
const { api } = buildHarness();
503526
let sampleCount = 0;
@@ -547,6 +570,7 @@ async function run() {
547570
await testRenderSanitizesTileSizeBeforeWasm();
548571
await testRenderSkipsInvalidTilesWithoutCrashing();
549572
await testAllTileCategoriesRenderWithWasm();
573+
await testMlResetCalledBeforeEachRender();
550574
console.log("Smoke tests passed.");
551575
}
552576

0 commit comments

Comments
 (0)