gama-platform / gama

Main repository for developing the 2024+ versions of GAMA
https://gama-platform.org
GNU General Public License v3.0
16 stars 5 forks source link

Models using the physics engine crash gama when closing the experiment #265

Closed lesquoyb closed 1 week ago

lesquoyb commented 2 months ago

Describe the bug Some models using the physics engine just crash gama completely after running for a few second and closing the experiment. There's no error message in the eclipse console

To Reproduce Steps to reproduce the behavior:

  1. Go to Eroding volcano.gaml or Falling.gaml
  2. Run it for at least a few seconds (it doesn't work if you close the experiment too soon)
  3. close the experiment
  4. See error

Additional context may be related to #242 Tested on windows and macos

lesquoyb commented 2 months ago

this file hs_err_pid8336.log is the error log I somehow managed to get when running gama from eclipse

lesquoyb commented 1 month ago

I tried upgrading to libbulletjme 21.2.1 but it didn't fix the problem

lesquoyb commented 1 month ago

I tried again but on another (windows) computer and with the latest libbullet (because why not update while we are at it), and this time no crash but I do have an error stack trace in the eclipse console:

> COMPIL: Eroding Vulcano.gaml                          in____________ 3ms

!ENTRY org.eclipse.core.resources 4 0 2024-07-17 17:29:13.306
!MESSAGE Error occurred while reading master table file
!STACK 0
java.nio.charset.MalformedInputException: Input length = 1
    at java.base/java.nio.charset.CoderResult.throwException(CoderResult.java:279)
    at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:405)
    at java.base/sun.nio.cs.StreamDecoder.lockedRead(StreamDecoder.java:217)
    at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:171)
    at java.base/java.io.InputStreamReader.read(InputStreamReader.java:186)
    at java.base/java.io.BufferedReader.fill(BufferedReader.java:160)
    at java.base/java.io.BufferedReader.implReadLine(BufferedReader.java:370)
    at java.base/java.io.BufferedReader.readLine(BufferedReader.java:347)
    at java.base/java.io.BufferedReader.readLine(BufferedReader.java:436)
    at java.base/java.nio.file.Files.readAllLines(Files.java:3400)
    at org.eclipse.core.internal.resources.SaveManager.getBadSequenceNumberErrorMessage(SaveManager.java:1670)
    at org.eclipse.core.internal.resources.SaveManager.validateMasterTableBeforeSave(SaveManager.java:1651)
    at org.eclipse.core.internal.resources.SaveManager.saveMasterTable(SaveManager.java:1330)
    at org.eclipse.core.internal.resources.SaveManager.saveMasterTable(SaveManager.java:1321)
    at org.eclipse.core.internal.resources.SaveManager.save(SaveManager.java:1294)
    at org.eclipse.core.internal.resources.SaveManager.save(SaveManager.java:1205)
    at org.eclipse.core.internal.resources.DelayedSnapshotJob.run(DelayedSnapshotJob.java:51)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

!ENTRY org.eclipse.core.jobs 4 2 2024-07-17 17:29:13.311
!MESSAGE An internal error occurred during: "Periodic workspace save.".
!STACK 0
java.lang.IllegalArgumentException: Cannot set lower sequence number for root (previous: 2, new: 1). Location: C:\Users\baptiste\Gama_Workspace\.metadata\.plugins\org.eclipse.core.resources\.safetable\org.eclipse.core.resourcesTimestamps and tree sequence numbers from file:
    at org.eclipse.core.runtime.Assert.isLegal(Assert.java:68)
    at org.eclipse.core.internal.resources.SaveManager.validateMasterTableBeforeSave(SaveManager.java:1652)
    at org.eclipse.core.internal.resources.SaveManager.saveMasterTable(SaveManager.java:1330)
    at org.eclipse.core.internal.resources.SaveManager.saveMasterTable(SaveManager.java:1321)
    at org.eclipse.core.internal.resources.SaveManager.save(SaveManager.java:1294)
    at org.eclipse.core.internal.resources.SaveManager.save(SaveManager.java:1205)
    at org.eclipse.core.internal.resources.DelayedSnapshotJob.run(DelayedSnapshotJob.java:51)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
java.lang.NullPointerException: Cannot invoke "gama.core.metamodel.shape.GamaPoint.getY()" because "o[0]" is null
    at gaml.additions.core.GamlAdditions.lambda$192(GamlAdditions.java:259)
    at gama.gaml.expressions.operators.UnaryOperator._value(UnaryOperator.java:99)
    at gama.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at gama.gaml.expressions.operators.BinaryOperator._value(BinaryOperator.java:148)
    at gama.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at gama.gaml.operators.Points.toPoint(Points.java:109)
    at gaml.additions.core.GamlAdditions.lambda$792(GamlAdditions.java:844)
    at gama.gaml.expressions.operators.AbstractNAryOperator._value(AbstractNAryOperator.java:388)
    at gama.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at gama.gaml.statements.SetStatement.privateExecuteIn(SetStatement.java:163)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.runtime.IScope.execute(IScope.java:414)
    at gama.gaml.statements.RemoteSequence.privateExecuteIn(RemoteSequence.java:69)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.gaml.statements.AbstractStatementSequence.executeOn(AbstractStatementSequence.java:59)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.metamodel.population.GamaPopulation.createAgents(GamaPopulation.java:573)
    at gama.gaml.statements.CreateStatement.createAgents(CreateStatement.java:527)
    at gama.gaml.statements.CreateStatement.privateExecuteIn(CreateStatement.java:465)
    at gama.gaml.statements.CreateStatement.privateExecuteIn(CreateStatement.java:1)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.gaml.statements.AbstractStatementSequence.executeOn(AbstractStatementSequence.java:59)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.runtime.IScope.execute(IScope.java:414)
    at gama.gaml.statements.RemoteSequence.privateExecuteIn(RemoteSequence.java:69)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.gaml.statements.AbstractStatementSequence.executeOn(AbstractStatementSequence.java:59)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.gaml.statements.AskStatement.privateExecuteIn(AskStatement.java:229)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.gaml.statements.AbstractStatementSequence.executeOn(AbstractStatementSequence.java:59)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.runtime.IScope.execute(IScope.java:414)
    at gama.gaml.statements.AbstractStatementSequence.privateExecuteIn(AbstractStatementSequence.java:69)
    at gama.gaml.architecture.reflex.ReflexStatement.privateExecuteIn(ReflexStatement.java:90)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.gaml.statements.AbstractStatementSequence.executeOn(AbstractStatementSequence.java:59)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.runtime.IScope.execute(IScope.java:414)
    at gama.gaml.architecture.reflex.ReflexArchitecture.executeReflexes(ReflexArchitecture.java:126)
    at gama.gaml.architecture.reflex.ReflexArchitecture.executeOn(ReflexArchitecture.java:112)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.metamodel.agent.AbstractAgent.doStep(AbstractAgent.java:271)
    at gama.core.metamodel.agent.MinimalAgent.doStep(MinimalAgent.java:260)
    at gama.extension.physics.gaml.PhysicalSimulationAgent.doStep(PhysicalSimulationAgent.java:408)
    at gama.core.metamodel.agent.AbstractAgent.step(AbstractAgent.java:242)
    at gama.core.runtime.ExecutionScope.step(ExecutionScope.java:547)
    at gama.core.common.interfaces.IScopedStepable.step(IScopedStepable.java:27)
    at gama.core.runtime.concurrent.SimulationRunner$1.run(SimulationRunner.java:118)
Java error: nil value detected
    at gama.core.runtime.exceptions.GamaRuntimeException.create(GamaRuntimeException.java:72)
    at gama.gaml.expressions.operators.UnaryOperator._value(UnaryOperator.java:104)
    at gama.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at gama.gaml.expressions.operators.BinaryOperator._value(BinaryOperator.java:148)
    at gama.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at gama.gaml.operators.Points.toPoint(Points.java:109)
    at gaml.additions.core.GamlAdditions.lambda$792(GamlAdditions.java:844)
    at gama.gaml.expressions.operators.AbstractNAryOperator._value(AbstractNAryOperator.java:388)
    at gama.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
    at gama.gaml.statements.SetStatement.privateExecuteIn(SetStatement.java:163)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.runtime.IScope.execute(IScope.java:414)
    at gama.gaml.statements.RemoteSequence.privateExecuteIn(RemoteSequence.java:69)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.gaml.statements.AbstractStatementSequence.executeOn(AbstractStatementSequence.java:59)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.metamodel.population.GamaPopulation.createAgents(GamaPopulation.java:573)
    at gama.gaml.statements.CreateStatement.createAgents(CreateStatement.java:527)
    at gama.gaml.statements.CreateStatement.privateExecuteIn(CreateStatement.java:465)
    at gama.gaml.statements.CreateStatement.privateExecuteIn(CreateStatement.java:1)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.gaml.statements.AbstractStatementSequence.executeOn(AbstractStatementSequence.java:59)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.runtime.IScope.execute(IScope.java:414)
    at gama.gaml.statements.RemoteSequence.privateExecuteIn(RemoteSequence.java:69)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.gaml.statements.AbstractStatementSequence.executeOn(AbstractStatementSequence.java:59)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.gaml.statements.AskStatement.privateExecuteIn(AskStatement.java:229)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.gaml.statements.AbstractStatementSequence.executeOn(AbstractStatementSequence.java:59)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.runtime.IScope.execute(IScope.java:414)
    at gama.gaml.statements.AbstractStatementSequence.privateExecuteIn(AbstractStatementSequence.java:69)
    at gama.gaml.architecture.reflex.ReflexStatement.privateExecuteIn(ReflexStatement.java:90)
    at gama.gaml.statements.AbstractStatement.executeOn(AbstractStatement.java:47)
    at gama.gaml.statements.AbstractStatementSequence.executeOn(AbstractStatementSequence.java:59)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.runtime.IScope.execute(IScope.java:414)
    at gama.gaml.architecture.reflex.ReflexArchitecture.executeReflexes(ReflexArchitecture.java:126)
    at gama.gaml.architecture.reflex.ReflexArchitecture.executeOn(ReflexArchitecture.java:112)
    at gama.core.runtime.ExecutionScope.execute(ExecutionScope.java:510)
    at gama.core.runtime.IScope.execute(IScope.java:443)
    at gama.core.metamodel.agent.AbstractAgent.doStep(AbstractAgent.java:271)
    at gama.core.metamodel.agent.MinimalAgent.doStep(MinimalAgent.java:260)
    at gama.extension.physics.gaml.PhysicalSimulationAgent.doStep(PhysicalSimulationAgent.java:408)
    at gama.core.metamodel.agent.AbstractAgent.step(AbstractAgent.java:242)
    at gama.core.runtime.ExecutionScope.step(ExecutionScope.java:547)
    at gama.core.common.interfaces.IScopedStepable.step(IScopedStepable.java:27)
    at gama.core.runtime.concurrent.SimulationRunner$1.run(SimulationRunner.java:118)
Caused by: java.lang.NullPointerException: Cannot invoke "gama.core.metamodel.shape.GamaPoint.getY()" because "o[0]" is null
    at gaml.additions.core.GamlAdditions.lambda$192(GamlAdditions.java:259)
    at gama.gaml.expressions.operators.UnaryOperator._value(UnaryOperator.java:99)
    ... 55 more
Deleting simulation perspective and opening immediately the modeling perspective = false

So my guess was that this error went somewhat silent because it may have been executed on a different thread on my first computer and that's also why one is crashing and not the other.

In addition to this, I ran the experiment a second time after closing it without a crash, and this time when I tried to close the second experiment the whole simulation hangs half closed (toolbar disposed but the displays are still there), but gama is still working. I also noticed a few periodic workspace save errors at the same time, which I thought were solved, but maybe that's a different problem. You can see all that here:

https://github.com/user-attachments/assets/14032f1e-717f-48b6-bc41-70ff511d861a

And eclipse had a different error stack after that:

Exception in Application
java.util.ConcurrentModificationException
    at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1096)
    at java.base/java.util.ArrayList$Itr.next(ArrayList.java:1050)
    at com.bulletphysics.collision.dispatch.CollisionWorld.destroy(CollisionWorld.java:87)
    at gama.extension.physics.java_version.BulletPhysicalWorld.dispose(BulletPhysicalWorld.java:140)
    at gama.extension.physics.gaml.PhysicalSimulationAgent.dispose(PhysicalSimulationAgent.java:391)
    at gama.core.metamodel.population.GamaPopulation.killMembers(GamaPopulation.java:731)
    at gama.core.metamodel.population.GamaPopulation.dispose(GamaPopulation.java:454)
    at gama.core.kernel.simulation.SimulationPopulation.dispose(SimulationPopulation.java:121)
    at gama.core.kernel.experiment.ExperimentAgent.closeSimulations(ExperimentAgent.java:328)
    at gama.core.kernel.experiment.ExperimentAgent.dispose(ExperimentAgent.java:361)
    at gama.core.kernel.experiment.ExperimentPlan.dispose(ExperimentPlan.java:531)
    at gama.core.kernel.experiment.DefaultExperimentController.closeExperiment(DefaultExperimentController.java:169)
    at gama.core.kernel.experiment.DefaultExperimentController.close(DefaultExperimentController.java:157)
    at gama.core.runtime.GAMA.closeController(GAMA.java:257)
    at gama.core.runtime.GAMA.closeAllExperiments(GAMA.java:241)
    at gama.ui.experiment.commands.CancelRun.lambda$0(CancelRun.java:31)
    at java.base/java.lang.Thread.run(Thread.java:1570)

So given the nature of error messages and the fact that it has different behaviours on different computers, it seems like we are facing a threading problem, maybe caused by some changes in eclipse/swt/jdk 21 when we switched to eclipse 2024-06?

AlexisDrogoul commented 1 week ago

I'm able to reproduce the problem, but the stack trace you are showing does not concern the native libraries. Are you sure they are loaded ? A message like

> GAMA  : Native Bullet library                         loaded in_____ 308ms
Dp_Libbulletjme version 21.2.1 initializing

should appear in the console. Otherwise, GAMA falls back to the java version, which seems to exhibit this behavior.

AlexisDrogoul commented 1 week ago

Should be fixed by https://github.com/gama-platform/gama/commit/9c82f9da097d09891869c25d9aa66030782eced6. Please test !