Skip to content

Commit 2718683

Browse files
authored
2 parents b4a0b44 + 3c9e711 commit 2718683

File tree

1 file changed

+7
-3
lines changed
  • barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main

1 file changed

+7
-3
lines changed

barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ export class BarretenbergWasmMain extends BarretenbergWasmBase {
173173
const scratchDataPtr = this.msgpackOutputScratch + METADATA_SIZE;
174174
const scratchDataSize = this.MSGPACK_SCRATCH_SIZE - METADATA_SIZE;
175175

176-
// Get memory once and create DataView for all reads/writes (avoids creating multiple typed arrays)
177-
const mem = this.getMemory();
178-
const view = new DataView(mem.buffer);
176+
// Get memory and create DataView for writing IN values
177+
let mem = this.getMemory();
178+
let view = new DataView(mem.buffer);
179179

180180
// Write IN values: provide scratch buffer pointer and size to C++
181181
view.setUint32(outputPtrLocation, scratchDataPtr, true);
@@ -189,6 +189,10 @@ export class BarretenbergWasmMain extends BarretenbergWasmBase {
189189
this.call('bbfree', inputPtr);
190190
}
191191

192+
// Re-fetch memory after WASM call, as the buffer may have been detached if memory grew
193+
mem = this.getMemory();
194+
view = new DataView(mem.buffer);
195+
192196
// Read OUT values: C++ returns actual buffer pointer and size
193197
const outputDataPtr = view.getUint32(outputPtrLocation, true);
194198
const outputSize = view.getUint32(outputSizeLocation, true);

0 commit comments

Comments
 (0)