Dark Utilities

Dark Utilities

93M Downloads

crashes from Monolith

JoeSGT opened this issue ยท 6 comments

commented

https://pastebin.com/cWjpwevv

Caused by: java.util.ConcurrentModificationException
at net.darkhax.darkutils.features.monolith.FeatureMonolith.onMobSpawnCheck(FeatureMonolith.java:92)

it seem i am getting crash because of that it's starting to happen often
version i use it 1.12.2-1.8.193

commented

I believe this issue is caused by code added by Sponge. You should make an issue on their issue tracker and link back here. If they disagree that the issue is on their end, then maybe they can help point out the flaw in my code.

Relevant Code

    public static final Map<WorldServer, List<TileEntityMonolith>> LOADED_MONOLITHS = new HashMap<>();

    @SubscribeEvent
    public void onMobSpawnCheck (CheckSpawn event) {

        if (event.getWorld() instanceof WorldServer) {

            // This loop is cause of CME
            for (final TileEntityMonolith monolith : getMonoliths((WorldServer) event.getWorld())) {

                if (monolith.isInSameChunk(new BlockPos(event.getX(), event.getY(), event.getZ()))) {

                    monolith.onSpawnCheck(event);
                    break;
                }
            }
        }
    }

    public static List<TileEntityMonolith> getMonoliths (WorldServer world) {

        return LOADED_MONOLITHS.computeIfAbsent(world, key -> {
            return new ArrayList<>();
        });
    }
commented

Thanks for the insight @Eufranio There are actually a few ways that I was able to reproduce this issue. I have completely scrapped this system in favour of one that doesn't involve caching.

commented

You could call getMonoliths before start iterating and store it to a field. Would fix this issue.

commented

Same as the above but not using Sponge

https://pastebin.com/PxgHU7pF

commented

If the world isn't in the map, computeIfAbsent will try to compute and add a new value to it (while you're iterating), hence why the CME. Not sponge related.

commented