From 57421c8a585449c9a517160b4addc24e52ef8856 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 18 Sep 2007 23:29:49 +0000 Subject: [PATCH] There are many ways I could rant about this, but I'm going to try to keep it short and informative (and clean ><)... While testing the ability to go straight to someone in a game from My Whirled, I was getting decoding streaming problems (but only sometimes) when fetching the game data. After many hours of looking for the problem and swearing up and down that it was nothing but consistent, malicious bitrot, I've tracked it down to this. In Underwhirled Drift (which is the game I was testing this on), I have a couple of property arrays that get set when the game is first started up with this: _control.set(PLAYER_STATE, new Array(numPlayers)); This allows me to fill in the proper indices at a later time in random order. This was working fine for multi-player games, and after what I've discovered here, I think I can get away with something simpler, but that can wait for later. When this was getting encoded, the expected effect would be to encode a TypedArray with a null in each spot that is defined in the source array (numPlayers long). In fact, it was creating an empty, zero length TypedArray. I'm not sure why - but that was confusing the system somewhere along the line so that when that set of bytes was read back from the server on another client (for instance, when fetching the EZGameObject when trying to join an in-progress game). Of course, zero-length TypedArrays should go over the wire just fine, so I'm not entirely convinced that I've tracked down the entire problem (or if that is in fact the issue, then it needs to be addressed). The diffs here will cause the encoding and decoding to correctly pull nulls out of the array, and put them in the TypedArray. The moral of this story is to watch out for this construct: for each (var obj :Object in arr) { } ...it may not always be doing what you would rightfully expect... git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4827 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/ObjectMarshaller.as | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/as/com/threerings/util/ObjectMarshaller.as b/src/as/com/threerings/util/ObjectMarshaller.as index d627b915f..31e2d2e28 100644 --- a/src/as/com/threerings/util/ObjectMarshaller.as +++ b/src/as/com/threerings/util/ObjectMarshaller.as @@ -58,8 +58,8 @@ public class ObjectMarshaller if (encodeArrayElements && obj is Array) { var src :Array = (obj as Array); var dest :TypedArray = TypedArray.create(ByteArray); - for each (var o :Object in src) { - dest.push(encode(o, false)); + for (var ii :int = 0; ii < src.length; ii++) { + dest.push(encode(src[ii], false)); } return dest; } @@ -93,8 +93,8 @@ public class ObjectMarshaller if (encoded is TypedArray) { var src :TypedArray = (encoded as TypedArray); var dest :Array = []; - for each (var b :ByteArray in src) { - dest.push(decode(b)); + for (var ii :int = 0; ii < src.length; ii++) { + dest.push(decode(src[ii] as ByteArray)); } return dest; }