   }
   
   private func unloadGL() {
+    let previousContext = EAGLContext.currentContext()
+    
+    self.setCurrentContext()
+    
     glDeleteBuffers(1, &self.vertexBuffer)
     glDeleteBuffers(1, &self.indexBuffer)
     glDeleteVertexArraysOES(1, &self.vertexArray)
-    
-    if EAGLContext.currentContext() == self.glkView.context {
-      EAGLContext.setCurrentContext(nil)
-    }
+
+    EAGLContext.setCurrentContext(previousContext != self.glkView.context ? previousContext : nil)
+  }
+  
+  private func setCurrentContext() {
+    let isContextSet = EAGLContext.setCurrentContext(self.glkView.context)
+    assert(isContextSet, "Failed to set current context")
   }
   
   deinit {

import GLKit

final class OpenGLViewController: RevertGLKViewController {
  
  private var glkView: GLKView {
    return self.view as! GLKView
  }


extension OpenGLViewController: GLKViewDelegate {
  override func glkView(view: GLKView!, drawInRect rect: CGRect) {
    self.setCurrentContext()

    glClearColor(0.156862745, 0.156862745, 0.156862745, 1)
    glClear(GLenum(GL_COLOR_BUFFER_BIT))
    
