Dustley / VS_tournament-Vintage

VS2 Compitition mod
Apache License 2.0
5 stars 2 forks source link

VS Physics Thread crashes #8

Open A31Nesta opened 1 year ago

A31Nesta commented 1 year ago

I'm creating a drone (10 spinners in total) and after a while of flying the ship gets stuck in the air and the only way to solve it is to close minecraft and open it again. Looking at the log you can see that the VS Physics thread crashed during the execution of the applyForces function:

[14:16:08] [Physics thread/ERROR] [or.va.co.im.pi.VSPhysicsPipelineBackgroundTask/]: Error in physics pipeline background task
java.util.ConcurrentModificationException: null
    at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1013) ~[?:?] {}
    at java.util.ArrayList$Itr.next(ArrayList.java:967) ~[?:?] {}
    at org.valkyrienskies.tournament.ship.tournamentShipControl.applyForces(tournamentShipControl.java:179) ~[tournament-forge-1.0.0-beta3-0.6+f5dce4613f.jar%2369!/:?] {re:classloading}
    at org.valkyrienskies.core.impl.pipelines.VSPhysicsPipelineStage.tickPhysics(VSPhysicsPipelineStage.kt:138) ~[valkyrienskies-118-forge-2.1.0-beta.10+d84531555f.jar%2370!/:?] {re:classloading}
    at org.valkyrienskies.core.impl.pipelines.VSPipelineImpl.tickPhysics(VSPipelineImpl.kt:109) ~[valkyrienskies-118-forge-2.1.0-beta.10+d84531555f.jar%2370!/:?] {re:classloading}
    at org.valkyrienskies.core.impl.pipelines.VSPhysicsPipelineBackgroundTask.run(VSPhysicsPipelineBackgroundTask.kt:75) [valkyrienskies-118-forge-2.1.0-beta.10+d84531555f.jar%2370!/:?] {re:classloading}
    at org.valkyrienskies.core.impl.pipelines.VSPipelineImpl$physicsThread$1.invoke(VSPipelineImpl.kt:65) [valkyrienskies-118-forge-2.1.0-beta.10+d84531555f.jar%2370!/:?] {re:classloading}
    at org.valkyrienskies.core.impl.pipelines.VSPipelineImpl$physicsThread$1.invoke(VSPipelineImpl.kt:64) [valkyrienskies-118-forge-2.1.0-beta.10+d84531555f.jar%2370!/:?] {re:classloading}
    at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30) [kotlinforforge-3.11.0-all.jar%2363!/:?] {}
[14:16:08] [Physics thread/ERROR] [or.va.co.im.pi.VSPhysicsPipelineBackgroundTask/]: !!!!!!! VS PHYSICS THREAD CRASHED !!!!!!!

I'm using

and also CC: Tweaked and Valkyrien Computers but they're not really related to this problem because I had this exact same problem before installing computercraft while playing with my previous drone (9 spinners).

alex-s168 commented 1 year ago

im 99% sure thats a vs2 bug

A31Nesta commented 1 year ago

I thought it was because of the applyForces function that apparently runs on the physics thread. This function accesses some global variables so that's why I thought that the problem was in tournament and not vs2

Rubydesic commented 1 year ago

Yes, this is a race condition caused by tournament not using thread safe data structures to hold the balloons, spinners, etc. Maybe consider using a ConcurrentHashMap.newKeySet() instead of an ArrayList, which is both faster and also has O(1) delete as opposed to O(n) for ArrayList

https://github.com/ConstantDust/VS_tournament-Vintage/blob/f5dce4613ff974661674b8f5703de2152785d76b/common/src/main/kotlin/org/valkyrienskies/tournament/ship/tournamentShipControl.kt#L38-L41

Rubydesic commented 1 year ago

I see you use a thread-safe CopyOnWriteArrayList for Pulses but not for anything else for some reason.

alex-s168 commented 1 year ago

ah lol

im gonna fix that sometime