Separate update and render

Posted by NSAddict on Game Development See other posts from Game Development or by NSAddict
Published on 2012-11-23T12:24:32Z Indexed on 2012/11/23 17:20 UTC
Read the original article Hit count: 145

Filed under:
|

I'm programming a simple Snake in Java. I'm a complete newbie when it comes to Java and Game Developing, so please bear with me ;)

Until now, I have been using a UI thread, as well as a update-thread. The update thread just set the position, set the GameObjects, and so on.

I didn't think much of concurrency, but now I've come to a problem.

I wanted to modify the ArrayList<GameObject>, but it throws a java.util.ConcurrentModificationException.

With a little research I found out that this happens because the two threads are trying to access the variables at the same time.

But I didn't really find a way to prevent this. I thought about copying the array and swapping them out when the rendering is finished, but I would have to deep-copy them, which isn't really the best solution in my opinion. It probably eats up more CPU resources than a single-threaded game.

Are there any other ways to prevent this?

Thanks a lot for your help!

© Game Development or respective owner

Related posts about java

Related posts about multithreading