Fix memory growth handling
This commit is contained in:
parent
b4feff41f0
commit
db966c8cb8
21
web/Core.js
21
web/Core.js
|
@ -87,11 +87,8 @@ 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),
|
sim.image = new ImageData(sim.pixels, 384, 224);
|
||||||
384*224*4, sim, "pixels", Uint8ClampedArray
|
|
||||||
);
|
|
||||||
sim.image = new ImageData(sim.pixels, 384, 224);
|
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
sim.samples = this.#noalloc(
|
sim.samples = this.#noalloc(
|
||||||
|
@ -364,8 +361,10 @@ 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.image = new ImageData(sim.pixels, 384, 224);
|
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);
|
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(
|
||||||
|
|
Loading…
Reference in New Issue