From 963d22b2f5121e36e39ac425283ff72046f51003 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 9 Dec 2023 09:42:18 -0600 Subject: [PATCH] Add a potential fix to unconfigured C2ME crashing/log spam --- .../RegionFileStorageExternalCache.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/mimicObject/RegionFileStorageExternalCache.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/mimicObject/RegionFileStorageExternalCache.java index d5c346c70..94fc0a2c3 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/mimicObject/RegionFileStorageExternalCache.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/mimicObject/RegionFileStorageExternalCache.java @@ -1,11 +1,13 @@ package com.seibel.distanthorizons.common.wrappers.worldGeneration.mimicObject; import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment; +import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtIo; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.storage.RegionFile; import net.minecraft.world.level.chunk.storage.RegionFileStorage; +import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; import java.io.DataInputStream; @@ -17,9 +19,13 @@ import java.util.concurrent.locks.ReentrantLock; public class RegionFileStorageExternalCache implements AutoCloseable { + private static final Logger LOGGER = DhLoggerBuilder.getLogger(); + public final RegionFileStorage storage; public static final int MAX_CACHE_SIZE = 16; + public static boolean regionCacheNullPointerWarningSent = false; + /** * Present to reduce the chance that we accidentally break underlying MC code that isn't thread safe, * specifically: "it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap.getAndMoveToFirst()" @@ -98,6 +104,19 @@ public class RegionFileStorageExternalCache implements AutoCloseable } #endif } + catch (NullPointerException e) + { + // Can sometimes happen when other mods modify the region cache system (IE C2ME) + // instead of blowing up, just use DH's cache instead + + if (!regionCacheNullPointerWarningSent) + { + regionCacheNullPointerWarningSent = true; + LOGGER.warn("Unable to access Minecraft's chunk cache. This may be due to another mod changing said cache. Falling back to DH's internal cache."); + } + + break; + } finally { this.getRegionFileLock.unlock();