when theta=Pi/2 , phi becomes a fixed number you can "solve" this by setting theta 1.00001*Pi/2 but you know, it's ugly