Fix freezes with graphics contexts

- Add locks to prevent multiple threads from trying to do OpenGL stuff
at the same time