Index: /trunk/src/VBox/Additions/x11/vboxvideo/vboxutils.c
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/vboxutils.c	(revision 35266)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/vboxutils.c	(revision 35267)
@@ -195,5 +195,5 @@
 
     pVBox = pScrn->driverPrivate;
-    if (pVBox->fHaveHGSMI == FALSE)
+    if (pVBox->fHaveHGSMI == FALSE || pVBox->vtSwitch)
         return;
 
@@ -259,8 +259,4 @@
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     int rc = VINF_SUCCESS;
-    unsigned i;
-    uint32_t offVRAMBaseMapping, offGuestHeapMemory, cbGuestHeapMemory,
-             cScreens;
-    void *pvGuestHeapMemory;
 
     pVBox->cScreens = 1;
@@ -270,4 +266,31 @@
         return FALSE;
     }
+
+    /* Set up the dirty rectangle handler.  It will be added into a function
+     * chain and gets removed when the screen is cleaned up. */
+    if (ShadowFBInit2(pScreen, NULL, vboxHandleDirtyRect) != TRUE)
+    {
+        xf86DrvMsg(scrnIndex, X_ERROR,
+                   "Unable to install dirty rectangle handler for VirtualBox graphics acceleration.\n");
+        return FALSE;
+    }
+    return TRUE;
+}
+
+/**
+ * Initialise VirtualBox's accelerated video extensions.
+ *
+ * @returns TRUE on success, FALSE on failure
+ */
+static Bool
+vboxSetupVRAMVbva(ScrnInfoPtr pScrn, VBOXPtr pVBox)
+{
+    int rc = VINF_SUCCESS;
+    unsigned i;
+    uint32_t offVRAMBaseMapping, offGuestHeapMemory, cbGuestHeapMemory;
+    void *pvGuestHeapMemory;
+
+    if (!pVBox->fHaveHGSMI)
+        return FALSE;
     VBoxHGSMIGetBaseMappingInfo(pScrn->videoRam * 1024, &offVRAMBaseMapping,
                                 NULL, &offGuestHeapMemory, &cbGuestHeapMemory,
@@ -283,10 +306,10 @@
     if (RT_FAILURE(rc))
     {
-        xf86DrvMsg(scrnIndex, X_ERROR, "Failed to set up the guest-to-host communication context, rc=%d\n", rc);
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to set up the guest-to-host communication context, rc=%d\n", rc);
         return FALSE;
     }
     pVBox->cbView = pVBox->cbFramebuffer = offVRAMBaseMapping;
     pVBox->cScreens = VBoxHGSMIGetMonitorCount(&pVBox->guestCtx);
-    xf86DrvMsg(scrnIndex, X_INFO, "Requested monitor count: %u\n",
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Requested monitor count: %u\n",
                pVBox->cScreens);
     for (i = 0; i < pVBox->cScreens; ++i)
@@ -305,11 +328,7 @@
     rc = VBoxHGSMISendViewInfo(&pVBox->guestCtx, pVBox->cScreens,
                                vboxFillViewInfo, (void *)pVBox);
-
-    /* Set up the dirty rectangle handler.  It will be added into a function
-     * chain and gets removed when the screen is cleaned up. */
-    if (ShadowFBInit2(pScreen, NULL, vboxHandleDirtyRect) != TRUE)
-    {
-        xf86DrvMsg(scrnIndex, X_ERROR,
-                   "Unable to install dirty rectangle handler for VirtualBox graphics acceleration.\n");
+    if (RT_FAILURE(rc))
+    {
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to send the view information to the host, rc=%d\n", rc);
         return FALSE;
     }
@@ -767,5 +786,5 @@
 
     TRACE_ENTRY();
-    if (!pVBox->fHaveHGSMI)
+    if (!vboxSetupVRAMVbva(pScrn, pVBox))
         return FALSE;
     for (i = 0; i < pVBox->cScreens; ++i)
Index: /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c	(revision 35266)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c	(revision 35267)
@@ -1159,4 +1159,6 @@
 
     TRACE_ENTRY();
+    if (pVBox->fHaveHGSMI)
+        vboxEnableVbva(pScrn);
     pVBox->vtSwitch = FALSE;
 #ifdef VBOX_DRI
@@ -1173,6 +1175,4 @@
         return FALSE;
 #endif
-    if (pVBox->fHaveHGSMI)
-        vboxEnableVbva(pScrn);
     return TRUE;
 }
