I'm not sure but changing this line:
IF (c_trace(my.x,temp.x,ignore_me) > 0) {

to
IF (c_trace(my.x,temp.x,ignore_me) != 0) {

could solve the problem.
Reason:
c_trace returns a value smaller than zero if it hit a face/polygon from behind.
That happens is if the position it traces from is inside of a model.