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

    • I also have the same question, thank you for sharing it and I also found the answer.
    • So I had no clue what topic to put this under because its not really modding with forge but modding forge itself. So I have terrain generation mods that are only server side and Bungeecord that has Geyser packet translator so people on bedrock edition can play as well, but when a bedrock player connects it gets a unknown packet error. I tested the proxy on a Spigot server verifying it was forge. With no mods installed I still get the error. I got a wireshark log of it all and I found the packet where it aborts the connection due to the invalid packet but I have no clue how to stop it. When I still had the mods installed I disabled the forge handshake protocol but it did not fix the issue. If you know what part of forge is doing this or a way to fix it all together that would be awesome. I know modifying forge can end really baddy (definitely the handshake protocol) but I think that is my only fix here. Im open to any suggestions tho. I have run out of ideas to fix it so any help would be nice. Also it seems the packet id causing the connection error is 0xFE but im not sure cause the client also sends back a packet with that ID. I have a whole bunch of info collected so if you need any more information on the issue, I willing to give it, just not the ips on the wireshark log.
    • Okay, I got it working correctly now, but I'm not sure how to make it work with multiple blocks.   My Block Code:   package expanded.blocks; import javax.annotation.Nullable; import expanded.VanillaBuildingBlocks; import net.minecraft.block.BlockState; import net.minecraft.block.RotatedPillarBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.ToolType; public class CustomLog extends RotatedPillarBlock {            public CustomLog(Properties properties) {         super(properties);     }      @Override     @Nullable     public BlockState getToolModifiedState(BlockState state, World world, BlockPos pos, PlayerEntity player, ItemStack stack, ToolType toolType) {         return toolType == ToolType.AXE ? VanillaBuildingBlocks.acacia_log.defaultBlockState() : null;     } }
    • ? Registering the block and overriding a function inside the class are two completely different things
    • Ya but I'm not sure how I would actually add/implement it into the class correctly, and then registering the block correctly in my register class.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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