halfhp / androidplot

Charts and plots for Android
http://androidplot.com
Apache License 2.0
505 stars 159 forks source link

ConcurrentModificationException when using LineAndPointRenderer and calling plot.clear() #115

Closed tjohnn closed 2 years ago

tjohnn commented 2 years ago
java.util.ConcurrentModificationException
        at java.util.ArrayList$Itr.next(ArrayList.java:860)
        at com.androidplot.SeriesRegistry.contains(SeriesRegistry.java:130)
        at com.androidplot.xy.LineAndPointRenderer.cullPointsCache(LineAndPointRenderer.java:125)
        at com.androidplot.xy.LineAndPointRenderer$1.onBeforeDraw(LineAndPointRenderer.java:54)
        at com.androidplot.Plot.notifyListenersBeforeDraw(Plot.java:607)
        at com.androidplot.xy.XYPlot.notifyListenersBeforeDraw(XYPlot.java:333)
        at com.androidplot.Plot.renderOnCanvas(Plot.java:881)
        at com.androidplot.Plot.lambda$startBackgroundRendering$0$Plot(Plot.java:440)
        at com.androidplot.Plot$$ExternalSyntheticLambda0.run(Unknown Source:2)
        at java.lang.Thread.run(Thread.java:920)
halfhp commented 2 years ago

For performance reasons, Androidplot does not leverage immutability to avoid concurrency issues. Instead, an interface is exposed to allow users to synchronize their usage with Androidplot's rendering cycles. See more here. In your case it's likely simpler to just synchronize your two calls externally.