Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix ConcurrentModificationException #2

Merged
merged 1 commit into from
Apr 30, 2023

Conversation

ForgottenUmbrella
Copy link
Contributor

@ForgottenUmbrella ForgottenUmbrella commented Apr 29, 2023

See my comment on issue #1.

To summarise, PalladiumCore enables mod developers to deal with client-side setup in a cross-platform way. One thing that mods often do during client-side setup is call ItemProperties::register. This method is not thread-safe, which isn't a problem on Fabric since it doesn't run client-side setup in parallel for multiple mods, but it is a problem on Forge, which does. Looking at another mod that ran into this issue, my understanding is that we can avoid this concurrency error by using FMLClientSetupEvent::enqueueWork.

This PR attempts to fix the concurrency issue on PalladiumCore's side by blindly enqueuing client setup for all mods that register/listen for the CLIENT_SETUP event. A possible consequence of this is that loading mods on Forge takes longer.

To avoid that performance hit, we would need to be able to distinguish between listeners that don't need to be enqueued vs those that do, for example by providing two separate client events to register for. But this distinction only makes sense on Forge, so it could be awkward to expose this difference to mod developers.

I had considered providing the FMLClientSetupEvent instance as an argument to listeners and letting them call enqueueWork themselves, but that would expose a Forge-specific class. To get around that, you would have to create a compatibility class that is composed of FMLClientSetupEvent on Forge or whatever the equivalent is on Fabric, and then provides an enqueueWork method that delegates to FMLClientSetupEvent::enqueueWork on Forge and immediately runs the runnable on Fabric. But that sounds very clunky, and still doesn't solve the problem of hiding a Forge-only concern.

@Lucraft Lucraft changed the base branch from 1.19/main to 1.19/dev April 30, 2023 14:55
@Lucraft Lucraft merged commit 8c0aba2 into ThreeTAG:1.19/dev Apr 30, 2023
@Lucraft
Copy link
Member

Lucraft commented Apr 30, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants