Author Topic: [Lua] Crash calling RemoveSeedlings(int, int)  (Read 5834 times)

elideb

  • Seed
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
[Lua] Crash calling RemoveSeedlings(int, int)
« on: May 17, 2011, 07:34:40 AM »
When calling Asteroid:RemoveSeedlings (int faction, int number), the most frequent result is a game crash. If the command is invoked from console, the crash does not happen, and the output is:

"Index was out of range. Must be non-negative and less than the size of the collection."

The error does not happen if the number of seedlings to remove is 0 or there are 0 seedlings of the faction in the asteroid.

The attachment is a small test level. Move the RemoveSeedlings calls around to check different results.

Mihhaelo

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 67
Re: [Lua] Crash calling RemoveSeedlings(int, int)
« Reply #1 on: July 24, 2011, 07:12:02 AM »
I've had this issue before and I came to the conclusion that destroying seedlings is not instantaneous. I.E, a seedling in the process of being destroyed still counts as a seedling. Sometimes you're code will try and delete the same seedling twice and that's what causes the crash. Adding a time delay between subsequent removes fixes this (iirc).