mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-25 00:23:12 +09:00
fix(minimap): improve error handling and performance in tile parsing
- Add warning logging in renderChunkToPixels catch block before fallback - Switch maxTick filtering from skip/continue to early break (append-only optimization) - Use existsSync for directory existence check in loadExistingTagContent
This commit is contained in:
1 parent
9375c462af
commit
550ea22724
2 files changed
+8
-13
No files matched your search
@@ -819,7 +819,8 @@ export class ControllerPlugin extends BaseControllerPlugin {
|
|||||||
|
|
||||||
async loadExistingTagContent() {
|
async loadExistingTagContent() {
|
||||||
try {
|
try {
|
||||||
if (!await fs.pathExists(this.chartTagsPath)) {
|
// Use existsSync for synchronous directory existence check
|
||||||
|
if (!fs.existsSync(this.chartTagsPath)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ export async function renderChunkToPixels(chunkData: BinaryData): Promise<Uint16
|
|||||||
|
|
||||||
return pixels;
|
return pixels;
|
||||||
} catch (decompressError) {
|
} catch (decompressError) {
|
||||||
|
// Log warning before falling back to black pixels
|
||||||
|
console.warn(`Failed to decompress chunk data: ${decompressError}`);
|
||||||
// Return black pixels on error
|
// Return black pixels on error
|
||||||
return new Uint16Array(32 * 32);
|
return new Uint16Array(32 * 32);
|
||||||
}
|
}
|
||||||
@@ -153,17 +155,9 @@ async function processChunkData(
|
|||||||
const tick = readUInt32BE(tileData, offset) * 60; // Convert back to actual tick
|
const tick = readUInt32BE(tileData, offset) * 60; // Convert back to actual tick
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
// Skip this chunk if it's beyond our target tick
|
// Break early if this record is beyond our target tick (append-only optimization)
|
||||||
if (maxTick !== undefined && tick > maxTick) {
|
if (maxTick !== undefined && tick > maxTick) {
|
||||||
const chunkCoordsByte = readUInt8(tileData, offset);
|
return { success: false, newOffset: offset - 4 };
|
||||||
offset += 1;
|
|
||||||
const length = readUInt16BE(tileData, offset);
|
|
||||||
offset += 2;
|
|
||||||
if (offset + length > tileData.length) {
|
|
||||||
return { success: false, newOffset: offset };
|
|
||||||
}
|
|
||||||
offset += length; // Skip chunk data
|
|
||||||
return { success: true, newOffset: offset };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const chunkCoordsByte = readUInt8(tileData, offset);
|
const chunkCoordsByte = readUInt8(tileData, offset);
|
||||||
@@ -223,9 +217,9 @@ function processPixelData(
|
|||||||
return { success: false, newOffset: offset };
|
return { success: false, newOffset: offset };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip if beyond target tick
|
// Break early if this record is beyond our target tick (append-only optimization)
|
||||||
if (maxTick !== undefined && tick > maxTick) {
|
if (maxTick !== undefined && tick > maxTick) {
|
||||||
return { success: true, newOffset: offset + expectedDataLength };
|
return { success: false, newOffset: offset - 4 };
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < pixelCount; i++) {
|
for (let i = 0; i < pixelCount; i++) {
|
||||||
|
|||||||
Reference in new issue
Block a user