fix: recover from trimmed chunk (#2771)

- It's theoretically possible for the section FULL to return a null layer due to race condition with a trim operation
 - Locally cache result and if null, recover
 - I just had the error from #1592 again
 - This seems to have stopped the error, but adding logging did not log, so possibly some bigger bytecode changes?
 - Oh well
This commit is contained in:
Jordan 2024-06-17 17:40:59 +02:00 committed by GitHub
parent c7d6c907f1
commit 6a54c5bcb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,13 +17,23 @@ public abstract class CharBlocks implements IBlocks {
protected static final Section FULL = new Section() {
@Override
public char[] get(CharBlocks blocks, int layer) {
return blocks.blocks[layer];
char[] arr = blocks.blocks[layer];
if (arr == null) {
// Chunk probably trimmed mid-operations, but do nothing about it to avoid other issues
return EMPTY.get(blocks, layer, false);
}
return arr;
}
// Ignore aggressive switch here.
@Override
public char[] get(CharBlocks blocks, int layer, boolean aggressive) {
return blocks.blocks[layer];
char[] arr = blocks.blocks[layer];
if (arr == null) {
// Chunk probably trimmed mid-operations, but do nothing about it to avoid other issues
return EMPTY.get(blocks, layer, false);
}
return arr;
}
@Override