Fix a bug when testing collision with invalid tiles