Fix exception thrown during Lycanthropy transition#2565
Conversation
…n, to avoid issues with effects that add new bundles
Interkarma
left a comment
There was a problem hiding this comment.
I've approved this one, it fixes the problem for any effects that could trigger this (including vampirism, I assume, which works similarly).
I'd also like to offer an alternative approach. EntityEffectManager.DoMagicRound() uses bundlesToRemove collection to determine bundles scheduled for removal post magic round update process.
Of course, the problem here is that a bundle is being added to the collection mid-iteration, for which there's no current handling. So another approach would be to do something similar to bundlesToRemove except with adding bundles.
But cloning out the collection like you do here is perfectly fine. It's simple and easy to understand. There's only a small number of elements in instancedBundles at any one time, and they only tick every 5 seconds. So I have no problems if you folks run with this fix as-is.
I have considered it after your post. However, there is one issue that bugs me. Each time we add a bundle, there is an event. In the current code, it means that when OnAssignBundle is raised, the new bundle is already part of I feel this would be more complicated than the In short, nah, not doing that :) |
A user on Discord sent me this error during gameplay.
This error is easy to reproduce.
diseaseplayer werewolfto get Lycanthropy InfectionSo, during
EntityEffectManager.DoMagicRound(), we have this loopFor the
LycanthropyInfectioneffect,MagicRoundupdates the disease progress, until 3 days have passed and the dream sequence has been watched. This will callDeployFullBlownLycanthropy(), which is implemented byWereboarInfectionandWerewolfInfectionas thisThis is all happening still in the middle of the foreach loop above. As you can see, we're assigning a new bundle to the player's effect manager, which modifies
instancedBundlesif the bundle has any "live" effects (which Lycanthropy curse does). Modifying collections during iteration is not supported, so the error occurs.While the error does not break anything permanently as far as we know, it still prevents other effects from being processed for the rest of this magic round. This could happen more often with mods.