# HG changeset patch # User oshiro # Date 1549880679 -32400 # Node ID 1f3f2abc9c1bab2cd8c583351a402320354c4d9a # Parent 11f587612329482032555e662f691abe9437fdb2 fix zrleeBlocking diff -r 11f587612329 -r 1f3f2abc9c1b src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Thu Feb 07 17:04:10 2019 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Mon Feb 11 19:24:39 2019 +0900 @@ -632,7 +632,7 @@ * @throws UnsupportedEncodingException */ public void readSendData(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect) - throws Exception { + throws TransportException,UnsupportedEncodingException { LinkedList bufs = new LinkedList(); int BLOCKSIZE = 64 * 1024; int headerLen = rect.getEncodingType() == EncodingType.CHECK_DELAY ? 24 : 16; @@ -651,7 +651,11 @@ if (encoding == EncodingType.ZRLE.getId() || encoding == EncodingType.ZLIB.getId()) { if (true) { - zrleeBlocking(dataLen, reader, bytes, rect, context.getPixelFormat().bitsPerPixel/8, bufs, header); + try { + zrleeBlocking(dataLen, reader, bytes, rect, context.getPixelFormat().bitsPerPixel/8, bufs, header); + } catch (DataFormatException e) { + e.printStackTrace(); + } return; } // recompress into ZREE @@ -732,7 +736,7 @@ */ - private void zrleeBlocking(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect, int bytePerPixel, LinkedList bufs, ByteBuffer header) throws Exception { + private void zrleeBlocking(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect, int bytePerPixel, LinkedList bufs, ByteBuffer header) throws TransportException, DataFormatException { ByteBuffer len = multicastqueue.allocate(4); reader.readBytes(len.array(), 0, 4); len.limit(4); @@ -755,19 +759,23 @@ out.add(ByteBuffer.wrap(bytes)); int inputIndex = 0; ByteBuffer c1 = multicastqueue.allocate(deflate_size); - int x = rect.x, y = rect.y, w = 0, h = 0, w0 = 0, h0 = 0; + int x = rect.x, y = rect.y, w = 0, h = 0, w0 = 0, h0 = 0; int span = rect.width; while (inputIndex < inflate_size) { deflater.setInput(bytes,inputIndex,span * bytePerPixel); - if (c1.remaining() < span * bytePerPixel || inputIndex < inflate_size - span * bytePerPixel) { + if (c1.remaining() < span * bytePerPixel || inputIndex >= inflate_size - span * bytePerPixel) { deflater.deflate(c1,Deflater.FULL_FLUSH); c1.flip(); - writeUpdateRectangleWithHeader(c1,header,c1.remaining(),x+w,y+h,h-h0,w-w0); + try { + writeUpdateRectangleWithHeader(c1,header,c1.remaining(),x+w,y+h,rect.width,h-h0); + } catch (InterruptedException e) { + e.printStackTrace(); + } h0 = h; w0 = w; c1.reset(); } else { - deflater.deflate(c1); + deflater.deflate(c1,Deflater.SYNC_FLUSH); } w += span; if (w >= rect.width ) {