Fix ConcurrentModificationException in tick handlers#6
Open
BluSpring wants to merge 1 commit intoHellFirePvP:1.20.4from
Open
Fix ConcurrentModificationException in tick handlers#6BluSpring wants to merge 1 commit intoHellFirePvP:1.20.4from
BluSpring wants to merge 1 commit intoHellFirePvP:1.20.4from
Conversation
Collaborator
|
hey @BluSpring do you have an info on the cause of this, a crash log or anything like that? CME shouldnt really happen here to the best of my knowledge. Im curious if this is some mixin or something perhaps? If you have any more info we'd appreciate it! Ty for the pr |
Author
|
Basically, if you register/unregister a tick handler to the same TickManager directly inside the Reproducing the crash can be triggered by simply registering a new level type TickHandler to a TickManager, and unregistering it immediately within the tick, for instance: public class TickHandler implements ITickHandler {
@Override
public void tick(TickEvent.Type type, Object... objects) {
Observerlibrepro.tickManager.unregister(this);
}
@Override
public EnumSet<TickEvent.Type> getHandledTypes() {
return EnumSet.of(TickEvent.Type.LEVEL);
}
@Override
public boolean canFire(TickEvent.Phase phase) {
return phase == TickEvent.Phase.END;
}
@Override
public String getName() {
return "Test";
}
}@Mod(Observerlibrepro.MODID)
public class Observerlibrepro {
public static final String MODID = "observerlibrepro";
public static final TickManager tickManager = new TickManager();
public Observerlibrepro(IEventBus modEventBus, ModContainer modContainer) {
NeoForge.EVENT_BUS.register(this);
tickManager.attachListeners(NeoForge.EVENT_BUS);
tickManager.register(new TickHandler());
}
@SubscribeEvent
private void registerCommands(RegisterCommandsEvent event) {
// This is used only to register a new TickHandler while in the world, to verify that the CME crash has been fixed.
event.getDispatcher().register(Commands.literal("testaddtick").executes(ctx -> {
tickManager.register(new TickHandler());
return 1;
}));
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a tick handler is registered within a ticking event, the game crashes to a ConcurrentModificationException.
This PR solves that problem by replacing TickManager's LinkedList with a ConcurrentLinkedQueue.