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
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;
}
}
}