From ac297652de0de7611948f04622505a39a2ae5127 Mon Sep 17 00:00:00 2001 From: MJRLegends Date: Wed, 24 Apr 2024 22:34:04 +0100 Subject: [PATCH] Fixed a rare chance of ConcurrentModificationException in Custom Celestial Selection Screen during rendering (GuiCelestialSelection#drawCircles) and updating bodiesToRender list (Fixes issue #767) --- .../gui/screen/CustomCelestialSelection.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/mjr/extraplanets/client/gui/screen/CustomCelestialSelection.java b/src/main/java/com/mjr/extraplanets/client/gui/screen/CustomCelestialSelection.java index 2cf10bed1..4bfc46005 100644 --- a/src/main/java/com/mjr/extraplanets/client/gui/screen/CustomCelestialSelection.java +++ b/src/main/java/com/mjr/extraplanets/client/gui/screen/CustomCelestialSelection.java @@ -51,6 +51,8 @@ import net.minecraftforge.fml.common.Loader; public class CustomCelestialSelection extends GuiCelestialSelection { + + private List updatedBodiesToRender; // Make a temp list so we don't cause a rare chance of ConcurrentModificationException during rendering(GuiCelestialSelection#drawCircles) and updating bodiesToRender list. // Galaxy System private List galaxies = new ArrayList(); @@ -98,11 +100,12 @@ public CustomCelestialSelection(boolean mapMode, List possibleBod */ @Override public void initGui() { + this.updatedBodiesToRender = Lists.newArrayList(); + // Used to add only researched bodies from planet progressions & Event lists CustomCelestialGUIEvent.PreLoadingCelestialBodies preEvent = new CustomCelestialGUIEvent.PreLoadingCelestialBodies(); MinecraftForge.EVENT_BUS.post(preEvent); - - this.bodiesToRender.clear(); + for (SolarSystem solarSystem : GalaxyRegistry.getRegisteredSolarSystems().values()) { if(preEvent.bodyUnlocalizedNamesToIgnore.contains(solarSystem.getUnlocalizedName())) continue; @@ -110,7 +113,7 @@ public void initGui() { continue; if (solarSystem.getUnlocalizedParentGalaxyName().equalsIgnoreCase(this.currentGalaxyName)) { - this.bodiesToRender.add(solarSystem.getMainStar()); + this.updatedBodiesToRender.add(solarSystem.getMainStar()); } } for (Planet planet : GalaxyRegistry.getRegisteredPlanets().values()) { @@ -122,10 +125,10 @@ public void initGui() { if (planet.getParentSolarSystem().getUnlocalizedParentGalaxyName().equalsIgnoreCase(this.currentGalaxyName)) { if (Loader.isModLoaded("planetprogression")) { if (PlanetProgressionCompatibility.isResearched(Minecraft.getMinecraft().player, planet)) { - this.bodiesToRender.add(planet); + this.updatedBodiesToRender.add(planet); } } else { - this.bodiesToRender.add(planet); + this.updatedBodiesToRender.add(planet); } } } @@ -138,10 +141,10 @@ public void initGui() { if (moon.getParentPlanet() != null && moon.getParentPlanet().getParentSolarSystem().getUnlocalizedParentGalaxyName().equalsIgnoreCase(this.currentGalaxyName)) { if (Loader.isModLoaded("planetprogression")) { if (PlanetProgressionCompatibility.isResearched(Minecraft.getMinecraft().player, moon.getParentPlanet()) && PlanetProgressionCompatibility.isResearched(Minecraft.getMinecraft().player, moon)) { - this.bodiesToRender.add(moon); + this.updatedBodiesToRender.add(moon); } } else { - this.bodiesToRender.add(moon); + this.updatedBodiesToRender.add(moon); } } else if (moon.getParentPlanet() == null) MessageUtilities.fatalErrorMessageToLog(Constants.modID, "The moon " + moon.getUnlocalizedName() + " seems to have a null parent planet. Please check the log for other errors!"); @@ -156,10 +159,10 @@ public void initGui() { if (satellite.getParentPlanet().getParentSolarSystem().getUnlocalizedParentGalaxyName().equalsIgnoreCase(this.currentGalaxyName)) { if (Loader.isModLoaded("planetprogression")) { if (PlanetProgressionCompatibility.isResearched(Minecraft.getMinecraft().player, satellite.getParentPlanet())) { - this.bodiesToRender.add(satellite); + this.updatedBodiesToRender.add(satellite); } } else { - this.bodiesToRender.add(satellite); + this.updatedBodiesToRender.add(satellite); } } } @@ -1083,6 +1086,11 @@ public void drawButtons(int mousePosX, int mousePosY) { */ @Override public void drawScreen(int mousePosX, int mousePosY, float partialTicks) { + if(this.updatedBodiesToRender != null && this.updatedBodiesToRender.size() != 0) { + this.bodiesToRender.clear(); + this.bodiesToRender.addAll(this.updatedBodiesToRender); + this.updatedBodiesToRender.clear(); + } this.mousePosX = mousePosX; this.mousePosY = mousePosY; this.partialTicks = partialTicks;