Fix memory growth handling

This commit is contained in:
Guy Perfect 2024-12-26 14:13:13 -06:00
parent b4feff41f0
commit db966c8cb8
1 changed files with 14 additions and 7 deletions

View File

@ -87,11 +87,8 @@ new class Core {
this.sims.set(sim.pointer, sim);
// Video
sim.pixels = this.#noalloc(
this.GetExtPixels(sim.pointer),
384*224*4, sim, "pixels", Uint8ClampedArray
);
sim.image = new ImageData(sim.pixels, 384, 224);
sim.pixels = this.#getPixels(sim);
sim.image = new ImageData(sim.pixels, 384, 224);
// Audio
sim.samples = this.#noalloc(
@ -364,8 +361,10 @@ new class Core {
this.mallocs.set(buffer.pointer, buffer);
this.#updateTarget(buffer);
}
for (let sim of this.sims)
sim.image = new ImageData(sim.pixels, 384, 224);
for (let sim of this.sims.values()) {
sim.pixels = this.#getPixels(sim);
sim.image = new ImageData(sim.pixels, 384, 224);
}
}
@ -436,6 +435,14 @@ new class Core {
this.Realloc(buffer.pointer, 0);
}
// Register a sim's pixel buffer
#getPixels(sim) {
return this.#noalloc(
this.GetExtPixels(sim.pointer),
384*224*4, sim, "pixels", Uint8ClampedArray
);
}
// Allocate memory in WebAssembly and register the buffer
#malloc(count, target = null, assign = null, type = Uint8ClampedArray) {
return this.#noalloc(