Try if it works if you add the following line of code at the top of your function:
comment:
functions have a my pointer, if they are called from an entity it points to that entity.
If a level_load happens, all functions which have a my pointer unequal to NULL will be terminated.
So this could be the problem here. (just a guess)
edit: thanks lukas, didn't watch my typing here ;-)