From eabf4670fbf08e5107a18dfd1f4ce85548865c8c Mon Sep 17 00:00:00 2001
From: Joel Martin <github@martintribe.org>
Date: Fri, 27 Aug 2010 11:21:30 -0500
Subject: [PATCH] rfb.js/tight_png: fix indexed receive queue handling.

getCLength was not using the index (RQi) into the receive queue.
---
 include/rfb.js | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/rfb.js b/include/rfb.js
index 684c8f0..9df27d4 100644
--- a/include/rfb.js
+++ b/include/rfb.js
@@ -1348,9 +1348,7 @@ encHandlers.TIGHT_PNG = function display_tight_png() {
     //Util.Debug(">> display_tight_png");
     var ctl, cmode, clength, getCLength, color, img;
     //Util.Debug("   FBU.rects: " + FBU.rects);
-    //Util.Debug("   RQlen(): " + RQlen());
-    //Util.Debug("   RQ.slice(0,20): " + RQ.slice(0,20));
-
+    //Util.Debug("   starting RQ.slice(RQi,RQi+20): " + RQ.slice(RQi,RQi+20) + " (" + RQlen() + ")");
 
     FBU.bytes = 1; // compression-control byte
     if (RQlen() < FBU.bytes) {
@@ -1398,13 +1396,13 @@ encHandlers.TIGHT_PNG = function display_tight_png() {
     // Determine FBU.bytes
     switch (cmode) {
     case "fill":
-        RQ[RQi++]; // shift off ctl
+        RQi++; // shift off ctl
         color = RQshiftBytes(fb_depth);
         canvas.fillRect(FBU.x, FBU.y, FBU.width, FBU.height, color);
         break;
     case "jpeg":
     case "png":
-        clength = getCLength(RQ, 1);
+        clength = getCLength(RQ, RQi+1);
         FBU.bytes = 1 + clength[0] + clength[1]; // ctl + clength size + jpeg-data
         if (RQlen() < FBU.bytes) {
             Util.Debug("   waiting for TIGHT " + cmode + " bytes");
@@ -1424,8 +1422,7 @@ encHandlers.TIGHT_PNG = function display_tight_png() {
     }
     FBU.bytes = 0;
     FBU.rects -= 1;
-    //Util.Debug("   ending RQlen(): " + RQlen());
-    //Util.Debug("   ending RQ.slice(0,20): " + RQ.slice(0,20));
+    //Util.Debug("   ending RQ.slice(RQi,RQi+20): " + RQ.slice(RQi,RQi+20) + " (" + RQlen() + ")");
     //Util.Debug("<< display_tight_png");
     return true;
 };
-- 
2.18.1