Check that context exists before trying to pop context.
On some linux drivers (such as nvidia version 384.111 and 387.34) setting the context to zero causes a segfault so check before setting in cases where the destruction may be trying to pop to a zero context.