Skip to content

Commit

Permalink
fix: improve dashmap reference management
Browse files Browse the repository at this point in the history
  • Loading branch information
Mili committed Mar 1, 2025
1 parent 1a2b492 commit 1cbaad0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pumpkin-world/src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,21 +383,23 @@ impl Level {
let mut recv = recv;
while let Some((pos, data)) = recv.recv().await {
if let Some(data) = data {
let entry = loaded_chunks
let value = loaded_chunks
.entry(pos)
.or_insert_with(|| Arc::new(RwLock::new(data)));
let value = entry.clone();
.or_insert_with(|| Arc::new(RwLock::new(data)))
.value()
.clone();
send_chunk(false, value).await;
} else {
let loaded_chunks = loaded_chunks.clone();
let world_gen = world_gen.clone();
let gen_channel = gen_channel.clone();
rayon::spawn(move || {
let data = world_gen.generate_chunk(pos);
let entry = loaded_chunks
let value = loaded_chunks
.entry(pos)
.or_insert_with(|| Arc::new(RwLock::new(data)));
let value = entry.clone();
.or_insert_with(|| Arc::new(RwLock::new(data)))
.value()
.clone();
gen_channel
.blocking_send((value, true))
.expect("Failed to send chunk from generation thread!");
Expand Down

0 comments on commit 1cbaad0

Please sign in to comment.