Index: /trunk/src/VBox/Additions/common/crOpenGL/context.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/context.c	(revision 39630)
+++ /trunk/src/VBox/Additions/common/crOpenGL/context.c	(revision 39631)
@@ -346,7 +346,9 @@
 static DECLCALLBACK(void) stubContextDtor(void*pvContext)
 {
+    crHashtableLock(stub.windowTable);
     crHashtableLock(stub.contextTable);
     stubDestroyContextLocked((ContextInfo*)pvContext);
     crHashtableUnlock(stub.contextTable);
+    crHashtableUnlock(stub.windowTable);
 }
 #endif
@@ -1181,4 +1183,7 @@
     }
 
+    /* the lock order is windowTable->contextTable (see wglMakeCurrent_prox, glXMakeCurrent)
+     * this is why we need to take a windowTable lock since we will later do stub.windowTable access & locking */
+    crHashtableLock(stub.windowTable);
     crHashtableLock(stub.contextTable);
 
@@ -1201,4 +1206,5 @@
 #endif
     crHashtableUnlock(stub.contextTable);
+    crHashtableUnlock(stub.windowTable);
 }
 
Index: /trunk/src/VBox/Additions/common/crOpenGL/load.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/load.c	(revision 39630)
+++ /trunk/src/VBox/Additions/common/crOpenGL/load.c	(revision 39631)
@@ -340,5 +340,10 @@
     //delete all created contexts
     stubMakeCurrent( NULL, NULL);
+
+    /* the lock order is windowTable->contextTable (see wglMakeCurrent_prox, glXMakeCurrent)
+     * this is why we need to take a windowTable lock since we will later do stub.windowTable access & locking */
+    crHashtableLock(stub.windowTable);
     crHashtableWalk(stub.contextTable, hsWalkStubDestroyContexts, NULL);
+    crHashtableUnlock(stub.windowTable);
 
     /* shutdown, now trap any calls to a NULL dispatcher */
Index: /trunk/src/VBox/Additions/common/crOpenGL/stub.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/stub.c	(revision 39630)
+++ /trunk/src/VBox/Additions/common/crOpenGL/stub.c	(revision 39631)
@@ -125,4 +125,14 @@
 }
 
+static void stubWindowCleanupForContextsCB(unsigned long key, void *data1, void *data2)
+{
+    ContextInfo *context = (ContextInfo *) data1;
+
+    CRASSERT(context);
+
+    if (context->currentDrawable == data2)
+        context->currentDrawable = NULL;
+}
+
 void APIENTRY crWindowDestroy( GLint window )
 {
@@ -153,4 +163,7 @@
 #endif
         crForcedFlush();
+
+        crHashtableWalk(stub.contextTable, stubWindowCleanupForContextsCB, winInfo);
+
         crHashtableDelete(stub.windowTable, window, crFree);
 
