From ae5fcad5267ef261f5939a646a15667caaa25221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8A=E3=81=8D=E8=90=8C?= Date: Wed, 10 Sep 2025 18:25:45 +0200 Subject: [PATCH] fix edits not being sent sometimes due to faulty swap-delete algorithm --- static/chunk-allocator.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/static/chunk-allocator.js b/static/chunk-allocator.js index e353cdd..2334a09 100644 --- a/static/chunk-allocator.js +++ b/static/chunk-allocator.js @@ -293,7 +293,7 @@ export class AtlasAllocator { // Add for ticking return new Promise((resolve) => { - this.#pendingDownloads.push({ pbo, fence, resolve }); + this.#pendingDownloads.push({ pbo, fence, resolve, done: false }); }); } @@ -311,6 +311,8 @@ export class AtlasAllocator { for (let i = 0; i < this.#pendingDownloads.length; ++i) { let pending = this.#pendingDownloads[i]; + if (pending.done) console.error("pending download already done", i, pending); + let status = gl.getSyncParameter(pending.fence, gl.SYNC_STATUS); if (status == gl.SIGNALED) { // Transfer complete, fetch pixels back to an array buffer. @@ -322,19 +324,18 @@ export class AtlasAllocator { gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null); gl.deleteSync(pending.fence); + pending.done = true; + pending.resolve({ width: this.chunkSize, height: this.chunkSize, data: arrayBuffer, }); - let last = this.#pendingDownloads.pop(); - if (this.#pendingDownloads.length > 0) { - this.#pendingDownloads[i] = last; - --i; - } else { - break; // now empty - } + this.#pendingDownloads[i] = + this.#pendingDownloads[this.#pendingDownloads.length - 1]; + this.#pendingDownloads.pop(); + --i; } } }