Fix possible bug when attempt to write weight images.