I'm making more tests, but i finally managed to replicate the error: When you call a function located on a different slot that uses a global array (array declared outside the function), the program for some reason will have issues on performing a modification of the array. Your best bet is to make a dummy array inside the function to copy all the content of the source array.