architectury / architectury-api

An intermediary api aimed at easing development of multiplatform mods.
https://discord.architectury.dev/
GNU Lesser General Public License v3.0
310 stars 56 forks source link

Thread safety of ItemPropertiesRegistry.register on Forge #378

Open zbx1425 opened 1 year ago

zbx1425 commented 1 year ago

ItemPropertiesRegistry.register calls the vanilla ItemProperties.register, which does computeIfAbsent on a static HashMap, which is not thread safe. When calling it from CLIENT_SETUP which is called from the parallel executing FMLClientSetupEvent, there can be read/write conflicts with other mods and result in ConcurrentModificationException.

This is not an issue on Fabric since it doesn't execute entry point functions in multiple threads.

Is this an Architectury API issue, or if I should call ItemPropertiesRegistry.register from somewhere else? I've read the Architectury API documentation didn't notice entries mentioning thread safety.

AIDA64S commented 1 year ago

Yes, this happened to me too

coucoul38 commented 2 months ago

Oh yeah, my game just crashed because of this. "Architectury encountered an error during the common_stup event phase" java.util.ConcurrentModificationException: null