Also in the 'STATE==2' clause you use vec_dist(me.x,your.x) without checking if 'your' is NULL. It's always wise to check if a pointer is NULL before using it.