Page 1 of 1
The supplied index is out of bounds.
Posted: 23 Jan 2012, 12:48
by hellopaso
hello there,
got this error when I am trying to put long on server side
Code: Select all
SFSObject cellItem = new SFSObject();
cellItem.putLong("id", num);
num can be number from 0 to 5000
by the way, what are the maximum lengths for INT and for LONG?
Posted: 24 Jan 2012, 16:15
by Lapo
Sorry... which error?
Posted: 24 Jan 2012, 19:31
by hellopaso
The supplied index is out of bounds.
at flash.utils::ByteArray/writeBytes()
at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/core/SFSIOHandler.as:216]
at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/core/SFSIOHandler.as:90]
at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketData()[/Users/Lapo/Documents/Flex Builder 3/SFS2X_AS3_API/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:404]
Posted: 24 Jan 2012, 19:58
by Damace
Hi
Is num - a long? Did you use the L suffix when the value was assigned?
Minimum/Maximum values
byte: [-128; 127]
short: [-32,768; 32,767]
int: [-2,147,483,648; 2,147,483,647]
long: [-9,223,372,036,854,775,808; 9,223,372,036,854,775,807]
If the range is 0;5000 I would use a short or an int.
Posted: 24 Jan 2012, 20:31
by hellopaso
ok, solved the problem.
it was connected with the size of SFSObject.
I have read
http://docs2x.smartfoxserver.com/Develo ... t-sfsarray
and chosen shortArray as the best way for me.
but question:
what are limitations for SFSObjects?
Posted: 25 Jan 2012, 08:24
by Bax
hellopaso wrote:it was connected with the size of SFSObject.
Can you better explain how size was involved?
Posted: 25 Jan 2012, 09:14
by hellopaso
hi Bax,
I have 4000 objects
each Object have its ID, X pos, Y pos
once user entered the room, server have to send all information about objects.
so, I did sth crazy like:
Code: Select all
SFSObject objectToSend = new SFSObjec();
for (int i = 0; i < 4000; i++){
SFSObject singleItem = new SFSObject();
singleItem.putInt("id", objectID);
singleItem.putInt("x", objectXPos);
singleItem.putInt("y", objectYPis)
objectToSend.putSFSObject("i" + i, singleItem)
}
and while sending this stuff, I got error.
as each VAR is SHORT, I tried this:
Code: Select all
SFSObject objectToSend = new SFSObjec();
for (int i = 0; i < 4000; i++){
ArrayList<Short> collection = new ArrayList<Short>();
collection.add((short) objectID);
collection.add((short) objectXPos);
collection.add((short) objectYPis);
objectToSend.putShortArray("i" + i, collection)
}
and works fine now

Posted: 25 Jan 2012, 11:40
by Lapo
This is strange. We will try and see if we can reproduce the problem. Meanwhile I could recommend an optimization, since you have so many items in the collection.
Instead of creating 4000 small arrays why don't you create just one? You can fill one single Array<Short> with all groups of three values and then on the client simply grab each group moving the Array index in steps of 3.
This way your packet will shrink quite a lot and it will be sent faster.
Posted: 25 Jan 2012, 11:56
by Lapo
Also I tested your code using nested SFSObjects, using 4000 items each with 3 integers and I don't get any errors.
Posted: 25 Jan 2012, 11:58
by hellopaso
about reproducing problem,
strange thing was when I commented first line - the problem gone
when third line was commented - the problem gone
but when I commented second one - the problem was still there
Code: Select all
singleItem.putInt("id", objectID); // first line, objectID can be from 0 to 4000
singleItem.putInt("x", objectXPos); // second line, XPOS can be from 0 to 64
singleItem.putInt("y", objectYPos) // third line, YPOS can bre from 0 to 64
Re: The supplied index is out of bounds.
Posted: 12 Mar 2012, 11:27
by tortenazor
Hi,
I get this error myself as well. It happens very randomly and so far I haven't been able to reproduce the error or create a sequence of steps that reproduces it. I have a realtime multiplayer race when car's positions are broadcasted to all players. This error happens sometimes, it is very rare but when it happens the whole SFS as3 API becomes unresponsive and I have to reload the browser.
I think for and until now you could try catch that particular line so at least when that happens the API doesn't crash and only the offending packet is ignored.
Cheers
Re: The supplied index is out of bounds.
Posted: 13 Mar 2012, 21:38
by Lapo
Can you at least report the full stack trace of the error?
Re: The supplied index is out of bounds.
Posted: 13 Mar 2012, 23:56
by tortenazor
Hi,
here's the stack trace I get
at flash.utils::ByteArray/writeBytes()
at com.smartfoxserver.v2.core::SFSIOHandler/handlePacketData()
at com.smartfoxserver.v2.core::SFSIOHandler/onDataRead()
also I opened a post on the as3 API forum, sice i'm uncertain where this belongs
http://forums.smartfoxserver.com/viewto ... 19&t=13541
I'm sorry I can't provide more detailed info. I have spend lots of hours trying to reproduce the error myself and have not been able to do it. it simply happens sometimes. This is a race game where the cars positions are broadcasted to all players. The circuit is always the same so the range of positions is always the same. I'm clueless, this is why I suggested a try catch around that statement so at least the class doesn't stop working. Also when this happens the server continues to work normally and doesn't display any errors.
Thank you
Re: The supplied index is out of bounds.
Posted: 14 Mar 2012, 08:39
by Lapo
Make sure to upgrade to version 2.0.1
Also, if it happens randomly it is likely to fall in the category of a network error so, catching the error doesn't change the fact that the packet is lost.
Re: The supplied index is out of bounds.
Posted: 14 Mar 2012, 10:55
by tortenazor
Hello,
I have upgraded both the server and the client to the latest releases ( attaching screenshot to confirm )
I understand that network errors can happen and packets can be lost. My game is already designed to deal with that. My problem with that particular error is that when it happens my smartfox class stops dispatching any events or accepting any requests. Also I don't get any disconnected, reconnected, or any sort of error event. This mean I can't alert the user or manually reconnect or anything.
Also when this happens and while the browser is frozen due to lack of sfs events, looking at the server admin reports the user to be connected and working normally, and apparently the server still broadcasts the rest of the race to that particular client without any problems.
Thank you for your time