DylanCope / Evolving-Protozoa

An interactive environment where protozoa-like entities live, die, and have offspring whose behaviours and morphologies can change.
MIT License
237 stars 25 forks source link

Color parameter outside of expected range: Green #12

Open Bitals opened 1 year ago

Bitals commented 1 year ago

I left it running for some time, it hanged with the following error:

Exception in thread "main" java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Color parameter outside of expected range: Green
    at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:484)
    at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:540)
    at java.base/java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:567)
    at java.base/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:670)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:159)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:173)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
    at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:765)
    at protoevo.env.Tank.update(Tank.java:200)
    at protoevo.core.Simulation.update(Simulation.java:220)
    at protoevo.core.Simulation.simulate(Simulation.java:187)
    at protoevo.core.Application.run(Application.java:53)
    at protoevo.core.Application.main(Application.java:32)
Caused by: java.lang.IllegalArgumentException: Color parameter outside of expected range: Green
    at java.desktop/java.awt.Color.testColorValueRange(Color.java:312)
    at java.desktop/java.awt.Color.<init>(Color.java:397)
    at java.desktop/java.awt.Color.<init>(Color.java:371)
    at protoevo.biology.Cell.getColor(Cell.java:438)
    at protoevo.biology.Protozoan.see(Protozoan.java:177)
    at protoevo.biology.Protozoan.interact(Protozoan.java:254)
    at protoevo.biology.Protozoan.lambda$handleInteractions$0(Protozoan.java:325)
    at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
    at protoevo.biology.Protozoan.handleInteractions(Protozoan.java:325)
    at protoevo.env.Tank.updateCell(Tank.java:171)
    at protoevo.env.Tank.lambda$update$5(Tank.java:200)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
    at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:754)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

image image

David-Hari commented 1 year ago

I had the same problem. Not sure how it can happen, the code seems to be constructing a Color object from red, green and blue components, not a string name like "Green".

micutio commented 1 year ago

Per the stack trace it originates in Cell.getColor(). The green value calculated from the cell health is outside of the range [0,255]. Maybe it's a dead cell or the health is otherwise outside of the normal range.

Is there a configuration that makes the issue reproducible every time it's run?

Bitals commented 1 year ago

Is there a configuration that makes the issue reproducible every time it's run?

Every time it happened it did so after a long time (overnight for example), so unfortunately I do not have a save close enough to be useful.

David-Hari commented 1 year ago

It does not always happen and I don't know how to reproduce (it could happen to any of the thousands of cells that exist in the simulation). But if it's just a matter of the green component being outside the range then the solution would be as simple as clamping the red, green and blue values to [0, 255]. I mean, it doesn't really matter if the colour of a cell is "too" green unless that colour is not just for display but is also somehow being used in the calculations.