Fix crash at the end of encodes.