Fix some memory issues when closing preview UI too fast.
I'm not sure if this pthread usage is ideal, but it does seem to work on linux.
Merge branch 'master' of git@github.com:FacialTurd/The-Powder-Toy.git