TropicSapling/rotating-ais

Crash upon AI death

TropicSapling opened this issue · 10 comments

TypeError: ai[i] is undefined or something

Reason of error confirmed: ai[i] == [] for some reason.

Cause of that could possibly have to do with genRandGenes()

Cause seems to have to do with ai[i] becoming empty instead of "dead", making '
genRandGenes() push to the end of the array instead of using the existing spot, also causing this whole error because it's empty

Error confirmed to be coming from these lines of code:

for(i = 0; i < ai.length; i++) {
    ai[i] = ai_sorted[ai_sorted_old.indexOf(ai[i])]; // This is not working correctly
}

indexOf occasionally returns -1 which is causing the problem
which means ai_sorted_old does not contain all items from ai

This is due to something wrong with ai_sorted_old

My temp fix fixed the crash but now we got this new bug with the same reason. ai_sorted_old seems to update when ai_sorted is for some reason?

EDIT: ai_sorted_old problem was due to JS being annoying. Fixed.

Partly fixed in 06ceeb1

ai now seems to not be updated completely

Fixed, but now crash upon death happens again but not until quite late. Well since I atleast managed to delay it I'm closing this for now...