Hi guys!
So, I’ve got the following setup:
A class “Game” and a class “RenderController”.
The Game class handles the entire game logic like moving, collision checking, and so on.
I do this to have my FPS completely seperated from the actual game speed.
RenderController renders down elements from Game’s lists like one called “Entities”.
As soon as I call entities.add(), I get the well-known “ConcurrentModificationException”.
I assume everyone of you had this problem once already or knows it at least.
So I got three ideas on how to solve this, but first I want to ask you guys which one would be the best, or if anyone got a better idea.
Idea #1:
Merge the Game and Render class. Would be the easiest, but worst idea imho.
Idea #2:
Before rendering, run .clone(); on each list and iterate the cloned list. I don’t know if this could perform bad in some later stage of the game.
Idea #3:
Wait for the Render class to finish rendering, and then add the elements to list. I can imagine that this would extremely slow down the game, as the Game class would be handling that.
I’d really appreciate some tips and experiences you’ve made regarding this exception and how to avoid it.
Thanks!