Fix panic in chunk implementation when resizing data
On occasion, the data fixing mechanism introduced in would cause a palette
entry to exceed the maximum value supported by the bits per block value. The
solution was to resize the data array before correcting it to account for
the new palette entry.
@@ -331,22 +331,6 @@ impl ChunkSection {
palette.insert(insertion_index, block_id);
paletted_index = insertion_index;
- // Correct data, since palette entries after
- // the one which was inserted will be offsetted
- // by one.
- for x in 0..16 {
- for y in 0..16 {
- for z in 0..16 {
- let index = block_index(x, y, z);
-
- let entry = self.data.get(index);
- if entry >= insertion_index as u64 {
- self.data.set(index, entry + 1);
- }
- }
- }
- }
-
// Resize if necessary
if needed_bits((palette.len() - 1) as u64) > self.data.bits_per_value {
let new_bits_per_value = self.data.bits_per_value + 1;
@@ -373,6 +357,22 @@ impl ChunkSection {
self.data = new_data;
}
}
+
+ // Correct data, since palette entries after
+ // the one which was inserted will be offsetted
+ // by one.
+ for x in 0..16 {
+ for y in 0..16 {
+ for z in 0..16 {
+ let index = block_index(x, y, z);
+
+ let entry = self.data.get(index);
+ if entry >= insertion_index as u64 {
+ self.data.set(index, entry + 1);
+ }
+ }
+ }
+ }
}
}
} else {
