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

PopulationGraphGUI throws unexpected exception #1

Closed
slemonide opened this issue Apr 3, 2017 · 10 comments
Closed

PopulationGraphGUI throws unexpected exception #1

slemonide opened this issue Apr 3, 2017 · 10 comments

Comments

@slemonide
Copy link
Owner

At completely random times, PopulationGraphGUI throws the following error:

Exception in thread "JavaFX Application Thread" java.util.ConcurrentModificationException
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
	at java.util.ArrayList$Itr.next(ArrayList.java:851)
	at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1042)
	at javafx.scene.chart.LineChart.layoutPlotChildren(LineChart.java:468)
	at javafx.scene.chart.XYChart.layoutChartChildren(XYChart.java:731)
	at javafx.scene.chart.Chart$1.layoutChildren(Chart.java:94)
	at javafx.scene.Parent.layout(Parent.java:1087)
	at javafx.scene.Parent.layout(Parent.java:1093)
	at javafx.scene.Parent.layout(Parent.java:1093)
	at javafx.scene.Scene.doLayoutPass(Scene.java:552)
	at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2397)
	at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:354)
	at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:381)
	at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:510)
	at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
	at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
	at java.lang.Thread.run(Thread.java:745)

It could be related to update() method updating the dataSeries.getData() outside the JavaFX start() method.

@jsondoo
Copy link

jsondoo commented Apr 3, 2017

In PopulationGraphGUI.java, I'm trying to remove the unchecked call warning.

public void update(Observable o, Object arg) {
        if (arg.equals("tick")) {
                XYChart.Data<Integer,Integer> xydata = new XYChart.Data<>(WorldManager.getInstance().getGeneration(),
                        WorldManager.getInstance().getCells().size());
                dataSeries.getData().add(xydata);
                if (dataSeries.getData().size() > MAX_GENERATIONS) {
                    dataSeries.getData().remove(0);
                }
        }
    }

Unchecked call to 'add(E)' as a member of raw type 'java.util.List' when you try to add xydata
I doubt that will resolve the issue but it might be related

@slemonide
Copy link
Owner Author

I was implementing another class that uses WorldManager.getInstance().getCells() which was iterating over it and which was quite slow each iteration.

What I figured out is that due to the fact that WorldManager runs in a separate thread, world is modified while the function iterates over all cells. This is the cause of the problem.

@slemonide
Copy link
Owner Author

Now just need to figure out how to work with the same Collection from different threads.

@slemonide
Copy link
Owner Author

slemonide commented Apr 3, 2017

Apparently, iterator() is no help since elements are being added during the iteration by the tick() method.
Would it be reasonable to stop the thread while iterating?

@jsondoo
Copy link

jsondoo commented Apr 3, 2017

Oh nice. That sounds reasonable to me, you will just have to ensure that only one thread is accessing Collection using thread states. Ill give it a try later

@jsondoo
Copy link

jsondoo commented Apr 3, 2017

Also maybe using javafx.concurrent might help? http://docs.oracle.com/javafx/2/threads/jfxpub-threads.htm

@slemonide
Copy link
Owner Author

Good idea. Also, I am thinking about redesigning the system so that Observers can read just the differences, not the whole data.

@slemonide
Copy link
Owner Author

Apparently, deleting any relation between the database and the GUI doesn't solve the problem.

Probably, problem is partially due to the JavaFX.

@slemonide
Copy link
Owner Author

@slemonide
Copy link
Owner Author

Problem solved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants