fixed buffer crash error

Just a simple try/catch, works for me now.