The rule is that after the foul has been committed, if the fouled player commits any other violation, whether it be traveling, committing a foul himself,etc. before taking the shot, then the shot does not count. However, NBA referees often do a poor job of enforcing after-the-foul violations.