Script works but I'm getting an error after it completes

Started by loudent, April 21, 2015, 05:36:00 PM

loudent

Ok, I've been wrestling with this for days and I finally got a proof of concept working except I'm getting this error after the script finishes:

21.4.15 17:25:22.8945 [ERR] Unhandled exception in Server game loop
Exception System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   -------------------------stack-------------------------
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Collections.Generic.List`1.Enumerator.MoveNext()
   at jvMuEfWa4dI5JoCFn5h.qLinMVWiyGcCwUBomHI.LNLpgxUlx9(Double  )
   at vxVLwDhWYiEysuRM7sN.ml7y5YhuRUkrQAmipFF.<>c__DisplayClassc.<ServerTick>b__2()
   at yh4Zn3002uxc4RoZtM8.gAxJV70qX9ONgNlNcs7`1.FnFGVddIss(Func`1 function, Func`1 shouldAbortCheckFunction)
   at vxVLwDhWYiEysuRM7sN.ml7y5YhuRUkrQAmipFF.lPDtIYPk3R(Double  )
   at vxVLwDhWYiEysuRM7sN.ml7y5YhuRUkrQAmipFF.EaltAtbg4x()

The script can be found at https://www.dropbox.com/s/wmofwjt210nq4cg/ldt_JettisonCargo.js?dl=0

ai_enabled

Hi!
How often does it happen?
Usually it's nothing serious and caused by some limitations in the server engine and can happens sometimes even if you're playing without any mod. It doesn't cause any harm, but the exception is written to the log.
If it always happens after execution of the script from your mod, then upload the mod and we will test and fix it.
Regards!

loudent

It happens every time.

And the script I linked to in my original post is pretty much the entire mod.

ai_enabled

#3
Thanks for the script.
It will be fixed with the next build. It happens because you're adding a crate (which is a physics body) while the server iterating the list of the physics objects. So collection was modified and it stops processing it. However, it stops only for the current server frame and it will continue on the next frame, so this exception is just a warning for us, don't worry about it - it should works fine!
Regards!

loudent