Roughly Enough Items Fabric/Forge/NeoForge (REI)

Roughly Enough Items Fabric/Forge/NeoForge (REI)

40M Downloads

Async search mode is not thread-safe

Fourmisain opened this issue ยท 1 comments

commented

When REI is set to async search mode (which it is by default), ItemStack.getTooltip() can be executed by worker threads.
The issue with this is that getTooltip() is generally assumed to run on the main thread and it might not be thread-safe.

For a concrete example see TechReborn/TechReborn#2386, where it caused a ConcurrentModificationException.
It notably also uses Screen.hasShiftDown, which uses GLFW.glfwGetKey, which "must only be called from the main thread." according to the docs.

Registry.ITEM is another candidate which is not thread-safe and even the vanilla getTooltip() does have a reference to it, though this might not actually cause any issue, even when it's not thread-safe on paper.

It looks like this needs an API where items can opt-out/in of being processed by worker threads.

commented

Some methods (for getting the pressed state of keys) are now patched by REI to fix this. Please re-open this issue if new non thread-safe methods emerge.