Compact Machines

Compact Machines

72M Downloads

Potential CME due to registering game rules in mod construction

ChiefArug opened this issue ยท 3 comments

commented

I am not using performance mods.

  • Confirm

Description

In your mod constructor you make a call to your game rule class to register them:

public CompactMachinesCommon(IEventBus modBus, ModContainer modContainer) {
initConfigs(modContainer);
prepare();
registerEvents(modBus);
CMRegistries.setup(modBus);
CMGameRules.register();
}

This has the potential to cause a Concurrent Modification Exception because GameRules#register adds an entry to a non threadsafe map. Issues caused by this would be very hard to reproduce and hard to pin the blame on the cause (as only one modifier shows up in the stacktrace).

You should instead ensure the register method is called from the main thread by enqueuing it in the common setup event.

Mod Version

c028da8

Forge Version

N/A

Link to Crash Log

N/A

Screenshot (if available)

N/A

How to reproduce

Not easily

commented

This does not solve it. The common setup event is still executed in parallel, you need to use event.enqueueWork to enqueue it to run on the main thread.

commented

@robotgryphon not sure if you saw my above comment, the fix implemented does not solve it because the common setup event also runs in parallel. You need to use event.enqueWork to submit work to be done on the main thread.

commented

I did. It's wrapped in enqueueWork in the latest code and will be fixed in the next release.