From a920f02030467c2efed05b1f04b09b3c9bc23d8c Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 5 Dec 2007 02:09:59 +0000 Subject: [PATCH] Found and fixed the "Mother Fucker of a Bug(tm)" that was causing Zyraxxis to hork. Deep within our streaming code, ArrayMask objects were being created with zero length when streaming non-final arrays with a zero length. This tickled a "feature" of Adobe's IDataInput code, which reads *all available bytes* if you pass readBytes() a length of 0. What's really annoying is that this worked fine if you were notified of the zero-length array via a PropertySetEvent, because that event would come in on its own frame and so if the array's length was zero then there were no more bytes to read. But if you entered a game and had to receive all the usercode properties at once, it booched. There are clumps of my pulled-out hair all around my desk from that. And: this is ultimately my own fault, as my old code didn't handle the case of the passed-in ByteArray having 0 length. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4900 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/io/ObjectInputStream.as | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/as/com/threerings/io/ObjectInputStream.as b/src/as/com/threerings/io/ObjectInputStream.as index f50314503..0a53b5a0a 100644 --- a/src/as/com/threerings/io/ObjectInputStream.as +++ b/src/as/com/threerings/io/ObjectInputStream.as @@ -206,16 +206,18 @@ public class ObjectInputStream } public function readBytes (bytes :ByteArray, offset :uint = 0, - length :uint = 0) :void + length :int = -1) :void //throws IOError { - // IDataInput reads all available bytes if a length is not passed - // in. Protect against an easy error to make by using the length of - // the array - if (length === 0) { - length = bytes.length; + // if no length specified then fill the ByteArray + if (length == -1) { + length = bytes.length - offset; + } + // And, if we really want to read 0 bytes then just don't do anything, because an + // IDataInput will read *all available bytes* when the specified length is 0. + if (length > 0) { + _source.readBytes(bytes, offset, length); } - _source.readBytes(bytes, offset, length); } public function readDouble () :Number