Index: trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c	(revision 48355)
+++ trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu.c	(revision 48356)
@@ -535,6 +535,4 @@
     WindowInfo *window;
 
-    GLboolean showIt;
-
     if (id <= 0)
     {
@@ -588,6 +586,14 @@
     if (pCtx->currentWindow==pWindow)
     {
-        renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, pCtx->BltInfo.Base.id);
-        pCtx->currentWindow=0;
+        WindowInfo* pDummy = renderspuGetDummyWindow(pCtx->BltInfo.Base.visualBits);
+        if (pDummy)
+        {
+            renderspuPerformMakeCurrent(pDummy, 0, pCtx);
+        }
+        else
+        {
+            crWarning("failed to get dummy window");
+            renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, pCtx->BltInfo.Base.id);
+        }
     }
 }
@@ -596,4 +602,6 @@
 {
     GET_CONTEXT(pOldCtx);
+    WindowInfo * pOldWindow = pOldCtx ? pOldCtx->currentWindow : NULL;
+    CRASSERT(!pOldCtx == !pOldWindow);
     /* ensure no concurrent draws can take place */
     renderspuVBoxCompositorSet(window, NULL);
@@ -606,8 +614,15 @@
     {
         GET_CONTEXT(pNewCtx);
-        if (pNewCtx!=pOldCtx)
-        {
-            renderspuMakeCurrent(pOldCtx&&pOldCtx->currentWindow ? pOldCtx->currentWindow->BltInfo.Base.id:CR_RENDER_DEFAULT_WINDOW_ID, 0,
-                                     pOldCtx ? pOldCtx->BltInfo.Base.id:CR_RENDER_DEFAULT_CONTEXT_ID);
+        WindowInfo * pNewWindow = pNewCtx ? pNewCtx->currentWindow : NULL;
+        CRASSERT(!pNewCtx == !pNewWindow);
+
+        if (pOldWindow == window)
+            renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, CR_RENDER_DEFAULT_CONTEXT_ID);
+        else if (pNewCtx != pOldCtx || pOldWindow != pNewWindow)
+        {
+            if (pOldCtx)
+                renderspuPerformMakeCurrent(pOldWindow, 0, pOldCtx);
+            else
+                renderspuMakeCurrent(CR_RENDER_DEFAULT_WINDOW_ID, 0, CR_RENDER_DEFAULT_CONTEXT_ID);
         }
     }
@@ -1711,4 +1726,11 @@
 }
 
+static void renderspuReparentWindowCB(unsigned long key, void *data1, void *data2)
+{
+    WindowInfo *pWindow = (WindowInfo *)data1;
+
+    renderspu_SystemReparentWindow(pWindow);
+}
+
 DECLEXPORT(void) renderspuReparentWindow(GLint window)
 {
@@ -1725,4 +1747,10 @@
 
     renderspu_SystemReparentWindow(pWindow);
+
+    /* special case: reparent all internal windows as well */
+    if (window == CR_RENDER_DEFAULT_WINDOW_ID)
+    {
+        crHashtableWalk(render_spu.dummyWindowTable, renderspuReparentWindowCB, NULL);
+    }
 }
 
Index: trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_wgl.c
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_wgl.c	(revision 48355)
+++ trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_wgl.c	(revision 48356)
@@ -1222,5 +1222,6 @@
     {
         LONG_PTR oldVal = SetWindowLongPtr(window->hWnd, GWLP_USERDATA, (LONG_PTR)window);
-        Assert(!oldVal && GetLastError() == NO_ERROR);
+        DWORD winEr = GetLastError();
+        Assert(!oldVal && winEr == NO_ERROR);
     }
 
@@ -1311,5 +1312,4 @@
 static GLboolean renderspuChkActivateSharedContext(ContextInfo *sharedContext)
 {
-    GLint crWindow;
     WindowInfo *window;
 
@@ -1322,16 +1322,8 @@
         renderspuChkActivateSharedContext(sharedContext->shared);
 
-    crWindow = renderspuWindowCreate(sharedContext->visual->displayName, sharedContext->visual->visAttribs);
-    if (!crWindow)
-    {
-        crError("renderspuChkActivateSharedContext: renderspuWindowCreate failed!");
-        return GL_FALSE;
-    }
-
-    window = (WindowInfo *) crHashtableSearch(render_spu.windowTable, crWindow);
+    window = renderspuGetDummyWindow(sharedContext->visual->visAttribs);
     if (!window)
     {
-        crError("renderspuChkActivateSharedContext: crHashtableSearch failed!");
-        renderspuWindowDestroy(crWindow);
+        crError("renderspuChkActivateSharedContext: renderspuGetDummyWindow failed!");
         return GL_FALSE;
     }
@@ -1345,5 +1337,4 @@
     {
         crError( "Render SPU: (renderspuChkActivateSharedContext) Couldn't create the context for the window (error 0x%x)", GetLastError() );
-        renderspuWindowDestroy(crWindow);
         return GL_FALSE;
     }
@@ -1368,5 +1359,5 @@
              * various tables. This is hack which just hides the root case.
              */
-//            crWarning("Recreating window in renderspu_SystemMakeCurrent\n");
+            crWarning("Recreating window in renderspu_SystemMakeCurrent\n");
             renderspu_SystemDestroyWindow( window );
             renderspu_SystemVBoxCreateWindow( context->visual, window->visible, window );
