Skip to content

Commit

Permalink
fix web re-attach buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
albho committed Aug 20, 2024
1 parent 185d9c9 commit 01ee8ed
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions binding/web/src/orca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,8 @@ export class Orca {
throw new OrcaErrors.OrcaOutOfMemoryError('malloc failed: Cannot allocate memory');
}

const memoryBufferView = new DataView(this._wasmMemory.buffer);
const memoryBufferUint8 = new Uint8Array(this._wasmMemory.buffer);
let memoryBufferView = new DataView(this._wasmMemory.buffer);
let memoryBufferUint8 = new Uint8Array(this._wasmMemory.buffer);

const initStatus = await this._pvOrcaSynthesizeParamsInit(synthesizeParamsAddressAddress);
if (initStatus !== PvStatus.SUCCESS) {
Expand Down Expand Up @@ -690,6 +690,9 @@ export class Orca {
await this._pvFree(textAddress);
await this._pvOrcaSynthesizeParamsDelete(synthesizeParamsAddress);

memoryBufferView = new DataView(this._wasmMemory.buffer);
memoryBufferUint8 = new Uint8Array(this._wasmMemory.buffer);

if (synthesizeStatus !== PvStatus.SUCCESS) {
const messageStack = await Orca.getMessageStack(
this._pvGetErrorStack,
Expand Down Expand Up @@ -1017,17 +1020,17 @@ export class Orca {
throw new OrcaErrors.OrcaOutOfMemoryError('malloc failed: Cannot allocate memory');
}

let memoryBufferView: DataView;

const initStatus = await pv_orca_init(
accessKeyAddress,
modelPathAddress,
objectAddressAddress);
await pv_free(accessKeyAddress);
await pv_free(modelPathAddress);

const memoryBufferView = new DataView(memory.buffer);
memoryBufferUint8 = new Uint8Array(memory.buffer);

if (initStatus !== PvStatus.SUCCESS) {
memoryBufferView = new DataView(memory.buffer);
memoryBufferUint8 = new Uint8Array(memory.buffer);
const messageStack = await Orca.getMessageStack(
pv_get_error_stack,
pv_free_error_stack,
Expand All @@ -1040,7 +1043,6 @@ export class Orca {
throw pvStatusToException(initStatus, 'Initialization failed', messageStack, pvError);
}

memoryBufferView = new DataView(memory.buffer);
const objectAddress = memoryBufferView.getInt32(objectAddressAddress, true);
await pv_free(objectAddressAddress);

Expand All @@ -1053,7 +1055,6 @@ export class Orca {
}
const sampleRateStatus = await pv_orca_sample_rate(objectAddress, sampleRateAddress);
if (sampleRateStatus !== PvStatus.SUCCESS) {
memoryBufferUint8 = new Uint8Array(memory.buffer);
const messageStack = await Orca.getMessageStack(
pv_get_error_stack,
pv_free_error_stack,
Expand All @@ -1078,7 +1079,6 @@ export class Orca {
}
const maxCharacterLimitStatus = await pv_orca_max_character_limit(objectAddress, maxCharacterLimitAddress);
if (maxCharacterLimitStatus !== PvStatus.SUCCESS) {
memoryBufferUint8 = new Uint8Array(memory.buffer);
const messageStack = await Orca.getMessageStack(
pv_get_error_stack,
pv_free_error_stack,
Expand Down Expand Up @@ -1116,7 +1116,6 @@ export class Orca {
validCharactersAddressAddressAddress,
);
if (validCharactersStatus !== PvStatus.SUCCESS) {
memoryBufferUint8 = new Uint8Array(memory.buffer);
const messageStack = await Orca.getMessageStack(
pv_get_error_stack,
pv_free_error_stack,
Expand All @@ -1133,7 +1132,6 @@ export class Orca {
const validCharactersAddressAddress = memoryBufferView.getInt32(validCharactersAddressAddressAddress, true);

const validCharacters: string[] = [];
memoryBufferUint8 = new Uint8Array(memory.buffer);
for (let i = 0; i < numCharacters; i++) {
const charIndex = memoryBufferView.getInt32(validCharactersAddressAddress + i * Int32Array.BYTES_PER_ELEMENT, true);
validCharacters.push(
Expand Down

0 comments on commit 01ee8ed

Please sign in to comment.