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

ConcurrentModificationException in Flora geneneration #9

Open
Cervator opened this issue Oct 6, 2019 · 0 comments
Open

ConcurrentModificationException in Flora geneneration #9

Cervator opened this issue Oct 6, 2019 · 0 comments

Comments

@Cervator
Copy link
Member

Cervator commented Oct 6, 2019

Was doing some testing and had a single chunk break due to a ConcurrentModificationException - looks like there might be some poor map handling around ExoplanetFloraRasterizer:86 - being that chunk gen is multithreaded this could happen, yet even without multiple threads maps can be sensitive when messed with during iteration.

Involved code snippet in method getRandomFlora:

        if (!flora.isEmpty()) {
            float rand = random.nextFloat(0, 1);
            float cumulativeProbability = 0.0f;

            for (Map.Entry<Block, Float> entry : flora.entrySet()) {
                cumulativeProbability += entry.getValue();
                if (rand <= cumulativeProbability) {
                    return entry.getKey();
                }
            }
        }

Error snippet:

ConcurrentModificationException: null
	at java.util.HashMap$HashIterator.nextNode(HashMap.java:1437)
	at java.util.HashMap$EntryIterator.next(HashMap.java:1471)
	at java.util.HashMap$EntryIterator.next(HashMap.java:1469)
	at org.terasology.exoplanet.generator.rasterizers.ExoplanetFloraRasterizer.getRandomFlora(ExoplanetFloraRasterizer.java:86)
	at org.terasology.exoplanet.generator.rasterizers.ExoplanetFloraRasterizer.generateChunk(ExoplanetFloraRasterizer.java:66)
	at org.terasology.world.generation.WorldImpl.rasterizeChunk(WorldImpl.java:64)
	at org.terasology.world.generation.BaseFacetedWorldGenerator.createChunk(BaseFacetedWorldGenerator.java:75)
	at org.terasology.world.chunks.localChunkProvider.LocalChunkProvider$1.run(LocalChunkProvider.java:653)
	at org.terasology.utilities.concurrency.TaskProcessor.run(TaskProcessor.java:50)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Otherwise the world still seems to work well, including the portal to get there. Not sure why this was never added to the stable module lineup, must have been missed, so I'm adding it now. Belated nice work @PutawanDE ! :-)

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

No branches or pull requests

1 participant