mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Prevent CME when unloading InstanceContainer chunks
This commit is contained in:
parent
943aae7397
commit
c6d7dea2da
@ -58,7 +58,7 @@ public class InstanceContainer extends Instance {
|
||||
private ChunkGenerator chunkGenerator;
|
||||
// (chunk index -> chunk) map, contains all the chunks in the instance
|
||||
private final Long2ObjectMap<Chunk> chunks = Long2ObjectMaps.synchronize(new Long2ObjectOpenHashMap<>());
|
||||
// contains all the chunks to remove during the next instance tick
|
||||
// contains all the chunks to remove during the next instance tick, should be synchronized
|
||||
protected final Set<Chunk> scheduledChunksToRemove = new HashSet<>();
|
||||
|
||||
private final ReadWriteLock changingBlockLock = new ReentrantReadWriteLock();
|
||||
@ -804,7 +804,7 @@ public class InstanceContainer extends Instance {
|
||||
* Unsafe because it has to be done on the same thread as the instance/chunks tick update.
|
||||
*/
|
||||
protected void UNSAFE_unloadChunks() {
|
||||
synchronized (this.scheduledChunksToRemove) {
|
||||
synchronized (scheduledChunksToRemove) {
|
||||
for (Chunk chunk : scheduledChunksToRemove) {
|
||||
final int chunkX = chunk.getChunkX();
|
||||
final int chunkZ = chunk.getChunkZ();
|
||||
|
@ -129,8 +129,12 @@ public final class InstanceManager {
|
||||
// Unload all chunks
|
||||
if (instance instanceof InstanceContainer) {
|
||||
InstanceContainer instanceContainer = (InstanceContainer) instance;
|
||||
instanceContainer.scheduledChunksToRemove.addAll(instanceContainer.getChunks());
|
||||
instanceContainer.UNSAFE_unloadChunks();
|
||||
|
||||
Set<Chunk> scheduledChunksToRemove = instanceContainer.scheduledChunksToRemove;
|
||||
synchronized (scheduledChunksToRemove) {
|
||||
scheduledChunksToRemove.addAll(instanceContainer.getChunks());
|
||||
instanceContainer.UNSAFE_unloadChunks();
|
||||
}
|
||||
}
|
||||
|
||||
instance.setRegistered(false);
|
||||
|
Loading…
Reference in New Issue
Block a user