Index: /trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
===================================================================
--- /trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp	(revision 54784)
+++ /trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp	(revision 54785)
@@ -845,5 +845,5 @@
 
     uint32_t                cContexts;
-    PVMSVGA3DCONTEXT        paContext;
+    PVMSVGA3DCONTEXT       *papContexts;
     uint32_t                cSurfaces;
     PVMSVGA3DSURFACE        paSurface;
@@ -898,5 +898,5 @@
 
     SSMFIELD_ENTRY(                 VMSVGA3DSTATE, cContexts),
-    SSMFIELD_ENTRY_IGN_HCPTR(       VMSVGA3DSTATE, paContext),
+    SSMFIELD_ENTRY_IGN_HCPTR(       VMSVGA3DSTATE, papContexts),
     SSMFIELD_ENTRY(                 VMSVGA3DSTATE, cSurfaces),
     SSMFIELD_ENTRY_IGN_HCPTR(       VMSVGA3DSTATE, paSurface),
@@ -1320,5 +1320,5 @@
 #ifdef VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE
     PVMSVGA3DSTATE pState = RT_FROM_MEMBER(pThis, VMSVGA3DSTATE, ShaderIf);
-    VMSVGA3D_SET_CURRENT_CONTEXT(pState, &pState->paContext[fOtherProfile ? 2 : 1]);
+    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pState->papContexts[fOtherProfile ? 2 : 1]);
 #else
     NOREF(pThis);
@@ -1444,5 +1444,5 @@
     AssertRCReturn(rc, rc);
 
-    pContext = &pState->paContext[1];
+    pContext = pState->papContexts[1];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -1468,7 +1468,7 @@
     rc = vmsvga3dContextDefineOgl(pThis, 2, VMSVGA3D_DEF_CTX_F_INIT | VMSVGA3D_DEF_CTX_F_OTHER_PROFILE);
     AssertLogRelRCReturn(rc, rc);
-    pContext = &pState->paContext[1]; /* Array may have been reallocated. */
-
-    pOtherCtx = &pState->paContext[2];
+    pContext = pState->papContexts[1]; /* Array may have been reallocated. */
+
+    pOtherCtx = pState->papContexts[2];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pOtherCtx);
 
@@ -1832,6 +1832,6 @@
     for (uint32_t i = 0; i < pState->cContexts; i++)
     {
-        if (pState->paContext[i].id != SVGA3D_INVALID_ID)
-            vmsvga3dContextDestroy(pThis, pState->paContext[i].id);
+        if (pState->papContexts[i]->id != SVGA3D_INVALID_ID)
+            vmsvga3dContextDestroy(pThis, pState->papContexts[i]->id);
     }
     return VINF_SUCCESS;
@@ -2815,5 +2815,5 @@
         for (uint32_t cid = 0; cid < pState->cContexts; cid++)
         {
-            pContext = &pState->paContext[cid];
+            pContext = pState->papContexts[cid];
             if (pContext->id == cid)
             {
@@ -2834,7 +2834,7 @@
         uint32_t cid = pSurface->idAssociatedContext;
         if (    cid <= pState->cContexts
-            &&  pState->paContext[cid].id == cid)
-        {
-            pContext = &pState->paContext[cid];
+            &&  pState->papContexts[cid]->id == cid)
+        {
+            pContext = pState->papContexts[cid];
             VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
         }
@@ -2845,7 +2845,7 @@
             for (cid = 0; cid < pState->cContexts; cid++)
             {
-                if (pState->paContext[cid].id == cid)
+                if (pState->papContexts[cid]->id == cid)
                 {
-                    pContext = &pState->paContext[cid];
+                    pContext = pState->papContexts[cid];
                     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
                     break;
@@ -3150,6 +3150,6 @@
 
 #ifdef VMSVGA3D_OGL_WITH_SHARED_CTX
-    if (idPrevCtx < pState->cContexts && pState->paContext[idPrevCtx].id == idPrevCtx)
-        VMSVGA3D_SET_CURRENT_CONTEXT(pState, &pState->paContext[idPrevCtx]);
+    if (idPrevCtx < pState->cContexts && pState->papContexts[idPrevCtx]->id == idPrevCtx)
+        VMSVGA3D_SET_CURRENT_CONTEXT(pState, pState->papContexts[idPrevCtx]);
 #endif
     return VINF_SUCCESS;
@@ -3197,10 +3197,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSurfaceStretchBlt invalid context id!\n"));
         AssertFailedReturn(VERR_INVALID_PARAMETER);
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 #endif
@@ -3477,10 +3477,10 @@
         uint32_t cid = pSurface->idAssociatedContext;
         if (    cid >= pState->cContexts
-            ||  pState->paContext[cid].id != cid)
-        {
-            Log(("vmsvga3dSurfaceDMA invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->paContext[cid].id));
+            ||  pState->papContexts[cid]->id != cid)
+        {
+            Log(("vmsvga3dSurfaceDMA invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->papContexts[cid]->id));
             AssertFailedReturn(VERR_INVALID_PARAMETER);
         }
-        PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
+        PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
 #endif
         VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
@@ -3830,10 +3830,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dGenerateMipmaps invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 #endif
@@ -3913,10 +3913,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dCommandPresent invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 #endif
@@ -4239,18 +4239,22 @@
         if (cid >= pState->cContexts)
         {
-            void *pvNew = RTMemRealloc(pState->paContext, sizeof(VMSVGA3DCONTEXT) * (cid + 1));
+            /* Grow the array. */
+            uint32_t cNew = RT_ALIGN(cid + 15, 16);
+            void *pvNew = RTMemRealloc(pState->papContexts, sizeof(pState->papContexts[0]) * cNew);
             AssertReturn(pvNew, VERR_NO_MEMORY);
-            pState->paContext = (PVMSVGA3DCONTEXT)pvNew;
-            memset(&pState->paContext[pState->cContexts], 0, sizeof(VMSVGA3DCONTEXT) * (cid + 1 - pState->cContexts));
-            for (uint32_t i = pState->cContexts; i < cid + 1; i++)
-                pState->paContext[i].id = SVGA3D_INVALID_ID;
-
-            pState->cContexts = cid + 1;
+            pState->papContexts = (PVMSVGA3DCONTEXT *)pvNew;
+            while (pState->cContexts < cNew)
+            {
+                pContext = (PVMSVGA3DCONTEXT)RTMemAllocZ(sizeof(*pContext));
+                AssertReturn(pContext, VERR_NO_MEMORY);
+                pContext->id = SVGA3D_INVALID_ID;
+                pState->papContexts[pState->cContexts++] = pContext;
+            }
         }
         /* If one already exists with this id, then destroy it now. */
-        if (pState->paContext[cid].id != SVGA3D_INVALID_ID)
+        if (pState->papContexts[cid]->id != SVGA3D_INVALID_ID)
             vmsvga3dContextDestroy(pThis, cid);
 
-        pContext = &pState->paContext[cid];
+        pContext = pState->papContexts[cid];
     }
 
@@ -4274,13 +4278,13 @@
     PVMSVGA3DCONTEXT pSharedCtx = NULL;
     for (uint32_t i = 0; i < pState->cContexts; i++)
-        if (   pState->paContext[i].id != SVGA3D_INVALID_ID
+        if (   pState->papContexts[i]->id != SVGA3D_INVALID_ID
             && i != cid
 # ifdef VBOX_VMSVGA3D_DUAL_OPENGL_PROFILE
-            && pState->paContext[i].fOtherProfile == RT_BOOL(fFlags & VMSVGA3D_DEF_CTX_F_OTHER_PROFILE)
+            && pState->papContexts[i]->fOtherProfile == RT_BOOL(fFlags & VMSVGA3D_DEF_CTX_F_OTHER_PROFILE)
 # endif
            )
         {
             Log(("Sharing display lists between cid=%d and cid=%d\n", pContext->id, i));
-            pSharedCtx = &pState->paContext[i];
+            pSharedCtx = pState->papContexts[i];
             break;
         }
@@ -4508,7 +4512,7 @@
 
     if (    cid < pState->cContexts
-        &&  pState->paContext[cid].id == cid)
-    {
-        PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
+        &&  pState->papContexts[cid]->id == cid)
+    {
+        PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
 
         Log(("vmsvga3dContextDestroy id %x\n", cid));
@@ -4644,5 +4648,5 @@
     for (uint32_t i = 0; i < pState->cContexts; i++)
     {
-        PVMSVGA3DCONTEXT pContext = &pState->paContext[i];
+        PVMSVGA3DCONTEXT pContext = pState->papContexts[i];
         uint32_t cid = pContext->id;
 
@@ -4683,10 +4687,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetTransform invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -4790,10 +4794,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetZRange invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -4932,10 +4936,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetRenderState invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -5767,10 +5771,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetRenderTarget invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -5839,5 +5843,5 @@
             VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
 
-            pContext = &pState->paContext[cid];
+            pContext = pState->papContexts[cid];
             VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 #else
@@ -6090,10 +6094,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetTextureState invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -6336,10 +6340,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetMaterial invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -6389,10 +6393,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetLightData invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -6568,10 +6572,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetLightEnabled invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -6605,10 +6609,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetViewPort invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -6653,10 +6657,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetClipPlane invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -6686,10 +6690,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetScissorRect invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -6725,10 +6729,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dCommandClear invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -7175,10 +7179,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dDrawPrimitives invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -7280,5 +7284,5 @@
                 VMSVGA3D_CHECK_LAST_ERROR(pState, pContext);
 
-                pContext = &pState->paContext[cid];
+                pContext = pState->papContexts[cid];
                 VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 #endif
@@ -7418,10 +7422,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dShaderDefine invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -7431,5 +7435,5 @@
         if (shid >= pContext->cVertexShaders)
         {
-            void *pvNew = RTMemRealloc(pContext->paVertexShader, sizeof(VMSVGA3DSHADER) * (shid + 1))
+            void *pvNew = RTMemRealloc(pContext->paVertexShader, sizeof(VMSVGA3DSHADER) * (shid + 1));
             AssertReturn(pvNew, VERR_NO_MEMORY);
             pContext->paVertexShader = (PVMSVGA3DSHADER)pvNew;
@@ -7518,10 +7522,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dShaderDestroy invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -7571,10 +7575,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dShaderSet invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
@@ -7644,10 +7648,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dShaderSetConst invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 
Index: /trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-shared.h
===================================================================
--- /trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-shared.h	(revision 54784)
+++ /trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-shared.h	(revision 54785)
@@ -52,5 +52,5 @@
             AssertRCReturn(rc, rc);
 
-            pContext = &pState->paContext[i];
+            pContext = pState->papContexts[i];
             AssertReturn(pContext->id == cid, VERR_INTERNAL_ERROR);
 
@@ -246,5 +246,5 @@
     for (uint32_t i = 0; i < pState->cContexts; i++)
     {
-        PVMSVGA3DCONTEXT pContext = &pState->paContext[i];
+        PVMSVGA3DCONTEXT pContext = pState->papContexts[i];
         uint32_t cid = pContext->id;
 
@@ -357,5 +357,5 @@
     for (uint32_t i = 0; i < pState->cContexts; i++)
     {
-        PVMSVGA3DCONTEXT pContext = &pState->paContext[i];
+        PVMSVGA3DCONTEXT pContext = pState->papContexts[i];
         uint32_t cid = pContext->id;
 
@@ -539,10 +539,10 @@
                                         uint32_t cid = pSurface->idAssociatedContext;
                                         if (    cid >= pState->cContexts
-                                            ||  pState->paContext[cid].id != cid)
+                                            ||  pState->papContexts[cid]->id != cid)
                                         {
-                                            Log(("vmsvga3dSaveExec invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->paContext[cid].id));
+                                            Log(("vmsvga3dSaveExec invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->papContexts[cid]->id));
                                             AssertFailedReturn(VERR_INVALID_PARAMETER);
                                         }
-                                        PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
+                                        PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
 
                                         hr = pSurface->bounce.pTexture->GetSurfaceLevel(i, &pDest);
@@ -655,10 +655,10 @@
                         uint32_t cid = pSurface->idAssociatedContext;
                         if (    cid >= pState->cContexts
-                            ||  pState->paContext[cid].id != cid)
-                        {
-                            Log(("vmsvga3dSaveExec: invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->paContext[cid].id));
+                            ||  pState->papContexts[cid]->id != cid)
+                        {
+                            Log(("vmsvga3dSaveExec: invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->papContexts[cid]->id));
                             AssertFailedReturn(VERR_INVALID_PARAMETER);
                         }
-                        PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
+                        PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
                         VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
 # endif
Index: /trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp
===================================================================
--- /trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp	(revision 54784)
+++ /trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp	(revision 54785)
@@ -343,7 +343,9 @@
     RTSEMEVENT              WndRequestSem;
 
+    /** The size of papContexts  */
     uint32_t                cContexts;
     uint32_t                cSurfaces;
-    PVMSVGA3DCONTEXT        paContext;
+    /** Contexts indexed by ID.  Grown as needed. */
+    PVMSVGA3DCONTEXT       *papContexts;
     PVMSVGA3DSURFACE        paSurface;
 
@@ -366,5 +368,5 @@
     SSMFIELD_ENTRY(                 VMSVGA3DSTATE, cContexts),
     SSMFIELD_ENTRY(                 VMSVGA3DSTATE, cSurfaces),
-    SSMFIELD_ENTRY_IGN_HCPTR(       VMSVGA3DSTATE, paContext),
+    SSMFIELD_ENTRY_IGN_HCPTR(       VMSVGA3DSTATE, papContexts),
     SSMFIELD_ENTRY_IGN_HCPTR(       VMSVGA3DSTATE, paSurface),
     SSMFIELD_ENTRY_IGNORE(          VMSVGA3DSTATE, fSupportedSurfaceINTZ),
@@ -600,6 +602,6 @@
     for (uint32_t i = 0; i < pState->cContexts; i++)
     {
-        if (pState->paContext[i].id != SVGA3D_INVALID_ID)
-            vmsvga3dContextDestroy(pThis, pState->paContext[i].id);
+        if (pState->papContexts[i]->id != SVGA3D_INVALID_ID)
+            vmsvga3dContextDestroy(pThis, pState->papContexts[i]->id);
     }
     return VINF_SUCCESS;
@@ -1618,5 +1620,5 @@
         for (uint32_t cid = 0; cid < pState->cContexts; cid++)
         {
-            PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
+            PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
             if (pContext->id == cid)
             {
@@ -1843,10 +1845,10 @@
         cid = pSurfaceSrc->idAssociatedContext;
         if (    cid >= pState->cContexts
-            ||  pState->paContext[cid].id != cid)
+            ||  pState->papContexts[cid]->id != cid)
         {
             Log(("vmsvga3dSurfaceCopy invalid context id!\n"));
             return VERR_INVALID_PARAMETER;
         }
-        pContext = &pState->paContext[cid];
+        pContext = pState->papContexts[cid];
 
         Log(("vmsvga3dSurfaceCopy: create texture surface id=%x type=%d format=%d -> create texture\n", sidDest, pSurfaceDest->flags, pSurfaceDest->format));
@@ -1865,10 +1867,10 @@
         cid = pSurfaceDest->idAssociatedContext;
         if (    cid >= pState->cContexts
-            ||  pState->paContext[cid].id != cid)
+            ||  pState->papContexts[cid]->id != cid)
         {
             Log(("vmsvga3dSurfaceCopy invalid context id!\n"));
             return VERR_INVALID_PARAMETER;
         }
-        pContext = &pState->paContext[cid];
+        pContext = pState->papContexts[cid];
 
         /* Must flush the other context's 3d pipeline to make sure all drawing is complete for the surface we're about to use. */
@@ -2211,10 +2213,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSurfaceStretchBlt invalid context id!\n"));
         AssertFailedReturn(VERR_INVALID_PARAMETER);
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     if (!pSurfaceSrc->u.pSurface)
@@ -2458,10 +2460,10 @@
                             uint32_t cid = pSurface->idAssociatedContext;
                             if (    cid >= pState->cContexts
-                                ||  pState->paContext[cid].id != cid)
+                                ||  pState->papContexts[cid]->id != cid)
                             {
-                                Log(("vmsvga3dSurfaceDMA invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->paContext[cid].id));
+                                Log(("vmsvga3dSurfaceDMA invalid context id (%x - %x)!\n", cid, (cid >= pState->cContexts) ? -1 : pState->papContexts[cid]->id));
                                 AssertFailedReturn(VERR_INVALID_PARAMETER);
                             }
-                            PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
+                            PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
 
                             /* @todo only sync when something was actually rendered (since the last sync) */
@@ -2527,10 +2529,10 @@
                             uint32_t cid = pSurface->idAssociatedContext;
                             if (    cid >= pState->cContexts
-                                ||  pState->paContext[cid].id != cid)
+                                ||  pState->papContexts[cid]->id != cid)
                             {
                                 Log(("vmsvga3dSurfaceDMA invalid context id!\n"));
                                 AssertFailedReturn(VERR_INVALID_PARAMETER);
                             }
-                            PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
+                            PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
 
                             Log(("vmsvga3dSurfaceDMA: sync texture from bounce buffer\n"));
@@ -2694,10 +2696,10 @@
 
             if (    cid >= pState->cContexts
-                ||  pState->paContext[cid].id != cid)
+                ||  pState->papContexts[cid]->id != cid)
             {
                 Log(("vmsvga3dGenerateMipmaps invalid context id!\n"));
                 return VERR_INVALID_PARAMETER;
             }
-            pContext = &pState->paContext[cid];
+            pContext = pState->papContexts[cid];
 
             if (pSurface->id == 0x5e)
@@ -2748,10 +2750,10 @@
 
         if (    cid >= pState->cContexts
-            ||  pState->paContext[cid].id != cid)
+            ||  pState->papContexts[cid]->id != cid)
         {
             Log(("vmsvga3dGenerateMipmaps invalid context id!\n"));
             return VERR_INVALID_PARAMETER;
         }
-        pContext = &pState->paContext[cid];
+        pContext = pState->papContexts[cid];
 
         /* Unknown surface type; turn it into a texture. */
@@ -2806,10 +2808,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dCommandPresent invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     hr = pContext->pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
@@ -2924,18 +2926,22 @@
     if (cid >= pState->cContexts)
     {
-        void *pvNew = RTMemRealloc(pState->paContext, sizeof(VMSVGA3DCONTEXT) * (cid + 1));
+        /* Grow the array. */
+        uint32_t cNew = RT_ALIGN(cid + 15, 16);
+        void *pvNew = RTMemRealloc(pState->papContexts, sizeof(pState->papContexts[0]) * cNew);
         AssertReturn(pvNew, VERR_NO_MEMORY);
-        pState->paContext = (PVMSVGA3DCONTEXT)pvNew;
-        memset(&pState->paContext[pState->cContexts], 0, sizeof(VMSVGA3DCONTEXT) * (cid + 1 - pState->cContexts));
-        for (uint32_t i = pState->cContexts; i < cid + 1; i++)
-            pState->paContext[i].id = SVGA3D_INVALID_ID;
-
-        pState->cContexts = cid + 1;
+        pState->papContexts = (PVMSVGA3DCONTEXT *)pvNew;
+        while (pState->cContexts < cNew)
+        {
+            pContext = (PVMSVGA3DCONTEXT)RTMemAllocZ(sizeof(*pContext));
+            AssertReturn(pContext, VERR_NO_MEMORY);
+            pContext->id = SVGA3D_INVALID_ID;
+            pState->papContexts[pState->cContexts++] = pContext;
+        }
     }
     /* If one already exists with this id, then destroy it now. */
-    if (pState->paContext[cid].id != SVGA3D_INVALID_ID)
+    if (pState->papContexts[cid]->id != SVGA3D_INVALID_ID)
         vmsvga3dContextDestroy(pThis, cid);
 
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     memset(pContext, 0, sizeof(*pContext));
     pContext->id               = cid;
@@ -3034,7 +3040,7 @@
 
     if (    cid < pState->cContexts
-        &&  pState->paContext[cid].id == cid)
-    {
-        PVMSVGA3DCONTEXT pContext = &pState->paContext[cid];
+        &&  pState->papContexts[cid]->id == cid)
+    {
+        PVMSVGA3DCONTEXT pContext = pState->papContexts[cid];
 
         Log(("vmsvga3dContextDestroy id %x\n", cid));
@@ -3176,5 +3182,5 @@
     for (uint32_t i = 0; i < pState->cContexts; i++)
     {
-        PVMSVGA3DCONTEXT pContext = &pState->paContext[i];
+        PVMSVGA3DCONTEXT pContext = pState->papContexts[i];
         uint32_t cid = pContext->id;
 
@@ -3428,10 +3434,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetTransform invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     switch (type)
@@ -3510,10 +3516,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetZRange invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     pContext->state.zRange = zRange;
     pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_ZRANGE;
@@ -3586,10 +3592,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetRenderState invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     for (unsigned i = 0; i < cRenderStates; i++)
@@ -4262,10 +4268,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetRenderTarget invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     /* Save for vm state save/restore. */
@@ -4688,10 +4694,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetTextureState invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     for (unsigned i = 0; i < cTextureStates; i++)
@@ -4950,10 +4956,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetMaterial invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     AssertReturn(face < SVGA3D_FACE_MAX, VERR_INVALID_PARAMETER);
@@ -5005,10 +5011,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetLightData invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     switch (pData->type)
@@ -5083,10 +5089,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetLightEnabled invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     /* Store for vm state save/restore */
@@ -5113,5 +5119,5 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetViewPort invalid context id!\n"));
@@ -5119,5 +5125,5 @@
     }
     /* Save for vm state save/restore. */
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
     pContext->state.RectViewPort = *pRect;
     pContext->state.u32UpdateFlags |= VMSVGA3D_UPDATE_VIEWPORT;
@@ -5149,10 +5155,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetClipPlane invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     /* Store for vm state save/restore. */
@@ -5177,10 +5183,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dCommandClear invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     if (clearFlag & SVGA3D_CLEAR_COLOR)
@@ -5389,5 +5395,5 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dDrawPrimitives invalid context id!\n"));
@@ -5395,5 +5401,5 @@
     }
 
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     /* Begin a scene before rendering anything. */
@@ -5677,10 +5683,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dSetScissorRect invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     /* Store for vm state save/restore. */
@@ -5712,10 +5718,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dShaderDefine invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     AssertReturn(shid < SVGA3D_MAX_SHADER_IDS, VERR_INVALID_PARAMETER);
@@ -5811,10 +5817,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dShaderDestroy invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     if (type == SVGA3D_SHADERTYPE_VS)
@@ -5862,10 +5868,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dShaderSet invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     if (type == SVGA3D_SHADERTYPE_VS)
@@ -5934,10 +5940,10 @@
 
     if (    cid >= pState->cContexts
-        ||  pState->paContext[cid].id != cid)
+        ||  pState->papContexts[cid]->id != cid)
     {
         Log(("vmsvga3dShaderSetConst invalid context id!\n"));
         return VERR_INVALID_PARAMETER;
     }
-    pContext = &pState->paContext[cid];
+    pContext = pState->papContexts[cid];
 
     for (uint32_t i = 0; i < cRegisters; i++)
