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