From 3bf0b8414543c9a6ccdba17b79c51863d25efad1 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 8 Jan 2025 14:53:07 -0800 Subject: [PATCH] Adjust error handling to try catching iOS error with more meaningful messaging. --- src/lib/nano-pow/classes/gpu.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lib/nano-pow/classes/gpu.ts b/src/lib/nano-pow/classes/gpu.ts index 1478673..e1bac77 100644 --- a/src/lib/nano-pow/classes/gpu.ts +++ b/src/lib/nano-pow/classes/gpu.ts @@ -36,7 +36,9 @@ export class NanoPowGpu { .then(device => { this.#device = device this.#device.lost.then(loss => { - console.warn(`(${loss.reason}) ${loss.message}. Reinitializing device.`) + console.dir(loss) + console.warn(loss.reason, loss.message) + console.warn(`Device lost. Reinitializing...`) this.init() }) @@ -166,13 +168,9 @@ export class NanoPowGpu { this.#device.queue.submit([commandEncoder.finish()]) // Read results back to Javascript and then unmap buffer after reading - try { await this.#cpuBuffer.mapAsync(GPUMapMode.READ) await this.#device.queue.onSubmittedWorkDone() - } catch (err) { - console.warn(`Error getting data from GPU, retrying. ${err}`) - return await this.search(hash, threshold) - } + try { const data = new DataView(this.#cpuBuffer.getMappedRange()) const nonce = data.getBigUint64(0, true) const found = !!data.getUint32(8) @@ -182,6 +180,10 @@ export class NanoPowGpu { const hex = nonce.toString(16).padStart(16, '0') return hex } else { + return await this.search(hash, threshold) + } + } catch (err) { + console.warn(`Error getting data from GPU, retrying. ${err}`) return await this.search(hash, threshold) } } -- 2.34.1