fix encode crash
Merge pull request #478 from volvet/fix-encode-crash

fix encode crash