Make more checks in sprite files to avoid crashes (fix #357).