fix edits not being sent sometimes due to faulty swap-delete algorithm

This commit is contained in:
りき萌 2025-09-10 18:25:45 +02:00
parent efaba55b54
commit ae5fcad526

View file

@ -293,7 +293,7 @@ export class AtlasAllocator {
// Add for ticking // Add for ticking
return new Promise((resolve) => { 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) { for (let i = 0; i < this.#pendingDownloads.length; ++i) {
let pending = this.#pendingDownloads[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); let status = gl.getSyncParameter(pending.fence, gl.SYNC_STATUS);
if (status == gl.SIGNALED) { if (status == gl.SIGNALED) {
// Transfer complete, fetch pixels back to an array buffer. // Transfer complete, fetch pixels back to an array buffer.
@ -322,19 +324,18 @@ export class AtlasAllocator {
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null); gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
gl.deleteSync(pending.fence); gl.deleteSync(pending.fence);
pending.done = true;
pending.resolve({ pending.resolve({
width: this.chunkSize, width: this.chunkSize,
height: this.chunkSize, height: this.chunkSize,
data: arrayBuffer, data: arrayBuffer,
}); });
let last = this.#pendingDownloads.pop(); this.#pendingDownloads[i] =
if (this.#pendingDownloads.length > 0) { this.#pendingDownloads[this.#pendingDownloads.length - 1];
this.#pendingDownloads[i] = last; this.#pendingDownloads.pop();
--i; --i;
} else {
break; // now empty
}
} }
} }
} }