Fix a data race

This commit is contained in:
IntegratedQuantum 2025-07-30 15:47:11 +02:00
parent e985c7c287
commit d02512a3e5
2 changed files with 14 additions and 5 deletions

View File

@ -343,11 +343,7 @@ pub const ChannelChunk = struct {
pub fn propagateUniformSun(self: *ChannelChunk, lightRefreshList: *main.List(chunk.ChunkPosition)) void {
std.debug.assert(self.isSun);
self.mutex.lock();
if(self.data.palette().len != 1) {
self.data.deferredDeinit();
self.data.init();
}
self.data.palette()[0].store(.fromArray(.{255, 255, 255}), .unordered);
self.data.fillUniform(.fromArray(.{255, 255, 255}));
self.mutex.unlock();
const val = 255 -| 8*|@as(u8, @intCast(self.ch.pos.voxelSize));
var lightQueue = main.utils.CircularBufferQueue(Entry).init(main.stackAllocator, 1 << 12);

View File

@ -1167,6 +1167,19 @@ pub fn PaletteCompressedRegion(T: type, size: comptime_int) type { // MARK: Pale
return impl.palette[0..impl.paletteLength];
}
pub fn fillUniform(self: *Self, value: T) void {
const impl = self.impl.raw;
if(impl.paletteLength == 1) {
impl.palette[0].store(value, .unordered);
return;
}
var newSelf: Self = undefined;
newSelf.init();
newSelf.impl.raw.palette[0] = .init(value);
newSelf.impl.raw = self.impl.swap(newSelf.impl.raw, .release);
newSelf.deferredDeinit();
}
fn getOrInsertPaletteIndex(noalias self: *Self, val: T) u32 {
var impl = self.impl.raw;
std.debug.assert(impl.paletteLength <= impl.palette.len);