fabric_getLoadedChunks() is not thread safe
pentyum opened this issue ยท 1 comments
The implementation of fabric_getLoadedChunks()
in WorldMixin.class is HashSet, and this is not thread safe. When I traverse it in another thread, if a chunk is unloaded at the same time, an exception java.util.ConcurrentModificationException: null
will be thrown.
That HashSet is implementation details.
It doesn't need to be thread safe because it is not accessed concurrently like you are trying to do.
If you want a thread safe view of loaded chunks you can make your own by listening to these events:
https://github.com/FabricMC/fabric/blob/1.18/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/api/client/event/lifecycle/v1/ClientChunkEvents.java