Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.4] WorldTickEvent Concurrent Access Exception


Recommended Posts

I have a low occurrence issue reported by users of my mod which is resulting in a ConcurrentModificationException. I'm currently trying to investigate some possible options, since I'm having problems duplicating the problem and my understanding of a couple of Minecraft areas is not good.

I've had a look at some of the Minecraft code, but I'm not understanding it well enough to satisfy my theories.

 

I have a WorldTickEvent handler in my mod, that simply walks a list of block positions using a iter.hasNext loop.

Each loop calls a simple piece of code on the current blockpos and then uses the iter.remove() to remove it from the list.

 

.....onWorldTick(TickEvent.WorldTickEvent event) .....
.... MultiBlockTracker.run()

[MultiBlockTracker.java]

public void run() {
....
Iterator<BlockPos> iter = blocks.iterator();
while (iter.hasNext()) {
    BlockPos pos = iter.next();
    TileEntity te = world.getTileEntity(pos);
    if (te instanceof MultiBlockGlueProvider) {
        ((MultiBlockGlueProvider)te).getGlue().onHello(world, i.getPos());
        iter.remove();
    }
}

 

Each relevant tile entity in my mod can add blocks to this block list via an override of the TileEntity.validate() method.

[MultiBlockTileEntity.java]
@Override
public void validate() {
    super.validate();
    if (!world.isRemote) {
        MultiBlockTracker.get().addEntry(pos);
    }
}

[MultiBlockTracker.java]
public void addEntry(BlockPos pos) {
    blocks.add(new BlockPos(pos));
}

 

The ConcurrentModificationException is pointing at the iter.next.

	
java.util.ConcurrentModificationException: null
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:909) ~[?:1.8.0_181] {}
	at java.util.ArrayList$Itr.next(ArrayList.java:859) ~[?:1.8.0_181] {}
	at ipsis.woot.modules.factory.multiblock.MultiBlockTracker.run(MultiBlockTracker.java:45) ~[woot:1.16.4-1.0.3.0] {re:classloading}

 

As far as I can see I am using the iterator correctly and have used the same pattern successfully(?) elsewhere in my code.

My current guess is that the concurrent modification is because one thread is trying to add to this list, while the other one is trying to remove items from it.

 

However I'm not sure if this is how Minecraft actually works, because I'm not confident in my understanding of the world tick.

 

So does anyone know what threads of execution are actually going on here

 

Can the world tick event and the tile entity validate be running in different threads causing this concurrent access to happen and I need to add some locking around the block list?

 

Or is there a different thread for each world meaning I could have two WorldTickEvent at the same time therefore I've got two iterators running over the same list removing items at the "same time"?

 

Or am I just looking at a red herring and the problem actually lies elsewhere?

 

Thanks

 

 

Link to post
Share on other sites

That is something I hadn't considered in terms of threads.

 

I have the WorldTickEvent handler do nothing on the client but run on the server.

I may have some paths for the addEntry running on both the client and server. Something I need to look into and check if that is where the conflict is coming from.

 

Thanks.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Alright, thanks once again for your support, have a great day
    • It works now, thank you very much. However, there is something else I'm wondering about. One mod, Netherite Plus, says that to config, I need to restart the game, but I did, twice, and the config option is still not available. (I use Mr. Crayfish's "Configured" to config mods). Do you know what's wrong?  
    • public static void generateOres(final BiomeLoadingEvent event) { if (!(event.getCategory().equals(Biome.Category.NETHER) || event.getCategory().equals(Biome.Category.THEEND))) { buildOreFeature(BlockInit.BERYLORE.get(), Blocks.GRASS, 10, 0, 100, 20); } } you're not actually adding the features to the biome, the return value of your method is just getting ignored, in mcp the method that you call is BiomeGenerationSettingsBuilder#withFeature, in mojmaps I don't know   private static ConfiguredFeature<?, ?> buildOreFeature(Block ore, Block filler, int maxVeinSize, int minVeinLevel, int maxVeinLevel, int spawnRate) { ConfiguredFeature<?, ?> feature = Feature.ORE.configured(new OreFeatureConfig(new BlockMatchRuleTest(filler), ore.defaultBlockState(), maxVeinSize)); feature = minMaxRange(feature, minVeinLevel, maxVeinLevel).squared(); feature = feature.count(spawnRate); return feature; } this is not how you should create a ConfiguredFeature 1- I suggest you keep each feature in a static field 2- you need to actually Register the feature, or the game won't know about it, you can do so by calling Registry.register, and registering your feature to the Configured Features registry which can be found under the class WorldGenRegistries 3- you can chain the count, squared and so on methods, it'll make your code look cleaner   MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, ModOreGen::generateOres); There's no need set it to a high priority, and you're registering the listener to the wrong event bus
    • So basically I tried updating my 1.12.2 ore generation to 1.16.5, long story short theres a massive change. I finally got it without eclipse problems through looking at a couple githubs, but it doesnt work. I feel like im overlooking an obvious problem but I cant see it. If someone could help me out that'd be great. Heres my code for the ore gen. @Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ModOreGen { public static void generateOres(final BiomeLoadingEvent event) { if (!(event.getCategory().equals(Biome.Category.NETHER) || event.getCategory().equals(Biome.Category.THEEND))) { buildOreFeature(BlockInit.BERYLORE.get(), Blocks.GRASS, 10, 0, 100, 20); } } private static ConfiguredFeature<?, ?> buildOreFeature(Block ore, Block filler, int maxVeinSize, int minVeinLevel, int maxVeinLevel, int spawnRate) { ConfiguredFeature<?, ?> feature = Feature.ORE.configured(new OreFeatureConfig(new BlockMatchRuleTest(filler), ore.defaultBlockState(), maxVeinSize)); feature = minMaxRange(feature, minVeinLevel, maxVeinLevel).squared(); feature = feature.count(spawnRate); return feature; } private static IDecoratable<ConfiguredFeature<?,?>> minMaxRange(IDecoratable<ConfiguredFeature<?,?>> f, int min, int max) { return f.decorated(Placement.RANGE.configured(new TopSolidRangeConfig(min, min, max))); } } And heres where I call it public Main() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::setup); ItemInit.ITEMS.register(bus); BlockInit.BLOCKS.register(bus); MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(FuelHandler.instance); PotionList.EFFECTS.register(bus); PotionList.POTIONS.register(bus); MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, ModOreGen::generateOres); }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.