Index: /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c	(revision 52450)
+++ /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_misc.c	(revision 52451)
@@ -565,23 +565,10 @@
     }
 
-#ifdef DEBUG_misha
-    if (pCurState->lists.currentIndex)
-    {
-        WARN(("GetError called in DisplayList"));
-    }
-#endif
-
-    if (!pCurState->lists.currentIndex || !(g_u32VBoxHostCaps & CR_VBOX_CAP_CMDBLOCKS))
-    {
-        packspuFlush( (void *) thread );
-        CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
-        if (pack_spu.swap)
-        {
-            return_val = (GLenum) SWAP32(return_val);
-        }
-    }
-    else
-    {
-        return_val = GL_NO_ERROR;
+    packspuFlush( (void *) thread );
+    CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
+
+    if (pack_spu.swap)
+    {
+        return_val = (GLenum) SWAP32(return_val);
     }
 
Index: /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_net.c
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_net.c	(revision 52450)
+++ /trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_net.c	(revision 52451)
@@ -250,6 +250,5 @@
     {
         g_u32VBoxHostCaps = crNetHostCapsGet();
-        if (g_u32VBoxHostCaps & CR_VBOX_CAP_CMDBLOCKS)
-            crPackCmdBlocksEnable();
+        crPackCapsSet(g_u32VBoxHostCaps);
     }
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/include/cr_pack.h
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/include/cr_pack.h	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/include/cr_pack.h	(revision 52451)
@@ -191,6 +191,5 @@
 extern DECLEXPORT(void) crPackExpandMultiDrawElementsEXTSWAP( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount, CRClientState *c, const GLfloat *pZva );
 
-extern DECLEXPORT(void) crPackCmdBlocksEnable();
-
+extern DECLEXPORT(void) crPackCapsSet(uint32_t u32Caps);
 
 /**
@@ -311,4 +310,18 @@
   } while (0)
 
+#define CR_CMDBLOCK_CHECK_FLUSH( pc )                               \
+  do {                                                              \
+    if (!(cr_packer_cmd_blocks_enabled & CR_VBOX_CAP_CMDBLOCKS_FLUSH)) break; \
+    if(!CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, CRPACKBLOCKSTATE_OP_NEWLIST)) break; \
+    THREADASSERT( pc );                                             \
+    CRASSERT( (pc)->currentBuffer );                                \
+    if ( !crPackCanHoldOpcode( pc, 1, 4 ) ) {                       \
+      (pc)->Flush( (pc)->flush_arg );                               \
+      Assert(crPackCanHoldOpcode( pc, 1, 4 ) );                     \
+    }                                                               \
+    CR_CMDBLOCK_OP( pc, CR_CMDBLOCKFLUSH_OPCODE );                  \
+    (pc)->Flush( (pc)->flush_arg );                                 \
+  } while (0)
+
 /**
  * Alloc space for a message of 'len' bytes (plus 1 opcode).
Index: /trunk/src/VBox/GuestHost/OpenGL/include/cr_protocol.h
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/include/cr_protocol.h	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/include/cr_protocol.h	(revision 52451)
@@ -51,6 +51,8 @@
 /* GetAttribsLocations support */
 #define CR_VBOX_CAP_GETATTRIBSLOCATIONS  0x00000008
-
-#define CR_VBOX_CAPS_ALL                 0x0000000f
+/* flush command blocks for execution  */
+#define CR_VBOX_CAP_CMDBLOCKS_FLUSH      0x00000010
+
+#define CR_VBOX_CAPS_ALL                 0x0000001f
 
 
Index: /trunk/src/VBox/GuestHost/OpenGL/include/cr_unpack.h
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/include/cr_unpack.h	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/include/cr_unpack.h	(revision 52451)
@@ -34,4 +34,5 @@
     CR_UNPACK_BUFFER_TYPE_GENERIC = 0,
     CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN,
+    CR_UNPACK_BUFFER_TYPE_CMDBLOCK_FLUSH,
     CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END
 } CR_UNPACK_BUFFER_TYPE;
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/opcodes.py
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/opcodes.py	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/opcodes.py	(revision 52451)
@@ -39,4 +39,6 @@
 enum_index = enum_index + 1
 print "\tCR_CMDBLOCKEND_OPCODE=%d," % enum_index
+enum_index = enum_index + 1
+print "\tCR_CMDBLOCKFLUSH_OPCODE=%d," % enum_index
 print "\tCR_NOP_OPCODE=255"
 if enum_index > 254:
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/pack_beginend.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/pack_beginend.c	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/pack_beginend.c	(revision 52451)
@@ -85,3 +85,2 @@
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
-
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/pack_bufferobject.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/pack_bufferobject.c	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/pack_bufferobject.c	(revision 52451)
@@ -100,4 +100,5 @@
 	WRITE_NETWORK_POINTER( 28, (void *) writeback );
 	WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
+	CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/pack_context.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/pack_context.c	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/pack_context.c	(revision 52451)
@@ -46,4 +46,5 @@
 	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 24, (void *) writeback );
 	WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
+	CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -78,4 +79,5 @@
 	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 24, (void *) writeback );
 	WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
+	CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -107,4 +109,5 @@
 	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 20, (void *) writeback );
 	WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
+	CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -135,4 +138,5 @@
 	WRITE_NETWORK_POINTER( DISPLAY_NAME_LEN + 20, (void *) writeback );
 	WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
+	CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/pack_init.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/pack_init.c	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/pack_init.c	(revision 52451)
@@ -18,5 +18,5 @@
 #endif
 
-int cr_packer_cmd_blocks_enabled = 0;
+uint32_t cr_packer_cmd_blocks_enabled = 0;
 
 CRPackContext *crPackNewContext( int swapping )
@@ -69,6 +69,6 @@
 }
 
-void crPackCmdBlocksEnable()
+void crPackCapsSet(uint32_t u32Caps)
 {
-    cr_packer_cmd_blocks_enabled = 1;
+    cr_packer_cmd_blocks_enabled = (u32Caps & (CR_VBOX_CAP_CMDBLOCKS_FLUSH | CR_VBOX_CAP_CMDBLOCKS));
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/pack_pixels.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/pack_pixels.c	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/pack_pixels.c	(revision 52451)
@@ -104,4 +104,5 @@
     WRITE_NETWORK_POINTER( 48, (char *) pixels );
     WRITE_OPCODE( pc, CR_READPIXELS_OPCODE );
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -220,4 +221,5 @@
     WRITE_NETWORK_POINTER( 32, (void *) writeback );
     WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/pack_program.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/pack_program.c	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/pack_program.c	(revision 52451)
@@ -282,4 +282,5 @@
     WRITE_NETWORK_POINTER(20 + n * sizeof(*programs), (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -300,4 +301,5 @@
     WRITE_NETWORK_POINTER( 16 + len + 8, (void *) writeback );
     WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -317,4 +319,5 @@
     WRITE_NETWORK_POINTER( 16 + len + 8, (void *) writeback );
     WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/pack_shaders.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/pack_shaders.c	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/pack_shaders.c	(revision 52451)
@@ -429,4 +429,5 @@
     WRITE_NETWORK_POINTER(28, (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -449,4 +450,5 @@
     WRITE_NETWORK_POINTER(28, (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -466,4 +468,5 @@
     WRITE_NETWORK_POINTER(24, (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -482,4 +485,5 @@
 	WRITE_NETWORK_POINTER(24, (void *) writeback);
 	WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+	CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -498,4 +502,5 @@
 	WRITE_NETWORK_POINTER(24, (void *) writeback);
 	WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+	CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -515,4 +520,5 @@
     WRITE_NETWORK_POINTER(24, (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -532,4 +538,5 @@
     WRITE_NETWORK_POINTER(24, (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -549,4 +556,5 @@
     WRITE_NETWORK_POINTER(24, (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -565,4 +573,5 @@
     WRITE_NETWORK_POINTER(24, (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -581,4 +590,5 @@
     WRITE_NETWORK_POINTER(24, (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -600,4 +610,5 @@
     WRITE_NETWORK_POINTER(8, (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
@@ -619,4 +630,5 @@
     WRITE_NETWORK_POINTER(8, (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/pack_swap_texture.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/pack_swap_texture.c	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/pack_swap_texture.c	(revision 52451)
@@ -685,4 +685,5 @@
     WRITE_NETWORK_POINTER( sizeof( int ) + 24 + n*sizeof( *textures ), (void *) writeback );
     WRITE_OPCODE( pc, CR_EXTEND_OPCODE );
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/pack_texture.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/pack_texture.c	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/pack_texture.c	(revision 52451)
@@ -719,4 +719,5 @@
     WRITE_NETWORK_POINTER(20 + n * sizeof(*textures), (void *) writeback);
     WRITE_OPCODE(pc, CR_EXTEND_OPCODE);
+    CR_CMDBLOCK_CHECK_FLUSH(pc);
     CR_UNLOCK_PACKER_CONTEXT(pc);
 }
Index: /trunk/src/VBox/GuestHost/OpenGL/packer/packer.py
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/packer/packer.py	(revision 52450)
+++ /trunk/src/VBox/GuestHost/OpenGL/packer/packer.py	(revision 52451)
@@ -211,4 +211,7 @@
         print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name )
 
+    if "get" in apiutil.Properties(func_name):
+        print '\tCR_CMDBLOCK_CHECK_FLUSH(pc);'
+
     print '\tCR_UNLOCK_PACKER_CONTEXT(pc);'
     print '}\n'
Index: /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server.h
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server.h	(revision 52450)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server.h	(revision 52451)
@@ -420,4 +420,5 @@
 int CrPMgrLoadState(PSSMHANDLE pSSM, uint32_t version);
 HCR_FRAMEBUFFER CrPMgrFbGet(uint32_t idScreen);
+int CrPMgrClearRegionsGlobal();
 /*cleanup stuff*/
 
Index: /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_config.c
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_config.c	(revision 52450)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_config.c	(revision 52451)
@@ -178,4 +178,5 @@
                 | CR_VBOX_CAP_CMDBLOCKS
                 | CR_VBOX_CAP_GETATTRIBSLOCATIONS
+                | CR_VBOX_CAP_CMDBLOCKS_FLUSH
                 ;
     }
@@ -328,4 +329,5 @@
                 | CR_VBOX_CAP_CMDBLOCKS
                 | CR_VBOX_CAP_GETATTRIBSLOCATIONS
+                | CR_VBOX_CAP_CMDBLOCKS_FLUSH
                 ;
     }
Index: /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp	(revision 52450)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp	(revision 52451)
@@ -4890,4 +4890,26 @@
 }
 
+int CrPMgrClearRegionsGlobal()
+{
+    for (HCR_FRAMEBUFFER hFb = CrPMgrFbGetFirstEnabled();
+            hFb;
+            hFb = CrPMgrFbGetNextEnabled(hFb))
+    {
+        int rc = CrFbUpdateBegin(hFb);
+        if (RT_SUCCESS(rc))
+        {
+            rc = CrFbRegionsClear(hFb);
+            if (RT_FAILURE(rc))
+            {
+                WARN(("CrFbRegionsClear failed %d", rc));
+            }
+
+            CrFbUpdateEnd(hFb);
+        }
+    }
+
+    return VINF_SUCCESS;
+}
+
 int CrPMgrModeVrdp(bool fEnable)
 {
Index: /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_stream.c
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_stream.c	(revision 52450)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_stream.c	(revision 52451)
@@ -655,7 +655,14 @@
             break;
         }
+        case CR_UNPACK_BUFFER_TYPE_CMDBLOCK_FLUSH: /* just flush for now */
+        {
+            CrPMgrClearRegionsGlobal(); /* clear regions to ensure we don't do MakeCurrent and friends */
+            crServerPendProcess(conn);
+            Assert(RTListIsEmpty(&conn->PendingMsgList));
+            break;
+        }
         case CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END:
         {
-            CRASSERT(!RTListIsEmpty(&conn->PendingMsgList));
+//            CRASSERT(!RTListIsEmpty(&conn->PendingMsgList));
             crServerPendProcess(conn);
             Assert(RTListIsEmpty(&conn->PendingMsgList));
Index: /trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack.py
===================================================================
--- /trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack.py	(revision 52450)
+++ /trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack.py	(revision 52451)
@@ -211,5 +211,4 @@
     const uint8_t *pu8Codes = (const uint8_t *)opcodes;
 
-    CR_UNPACK_BUFFER_TYPE enmType;
     uint8_t first;
     uint8_t last;
@@ -220,12 +219,14 @@
     first = pu8Codes[0];
     last = pu8Codes[1-(int)num_opcodes];
-
-    enmType = (first != CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN;
-
-    if (last != CR_CMDBLOCKEND_OPCODE)
-        return enmType;
-
-    /* last is CMDBLOCKEND*/
-    return (enmType == CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END;
+    
+    switch (last)
+    {
+        case CR_CMDBLOCKFLUSH_OPCODE:
+            return CR_UNPACK_BUFFER_TYPE_CMDBLOCK_FLUSH;
+        case CR_CMDBLOCKEND_OPCODE:
+            return (first == CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END;
+        default:
+            return (first != CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN;
+    } 
 }
 
@@ -288,4 +289,5 @@
             case CR_CMDBLOCKBEGIN_OPCODE:
             case CR_CMDBLOCKEND_OPCODE:
+            case CR_CMDBLOCKFLUSH_OPCODE:
             case CR_NOP_OPCODE:
                 INCR_DATA_PTR_NO_ARGS( );
