I saw this problem but it only occurred when the first part of the polyline was an arc. once it happened at the end of the polyline but that was also an arc segment.
I need to look into this more, I'm not sure if this function ever worked as planned? There must be something wrong in my angle calculation. I've spotted same problem in a similar function.I'll be back, thanks for the attached sample.