Thank you all for your help! I found the bug location. It was rotationIncrement quaternion in function RotateTowards. I just added:
if (glm::any(glm::isnan(rotationIncrement))) return from;
and it worked.