The supplied index is out of bounds.

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Post Reply
hellopaso
Posts: 43
Joined: 10 Dec 2011, 12:41

The supplied index is out of bounds.

Post 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?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Sorry... which error?
Lapo
--
gotoAndPlay()
...addicted to flash games
hellopaso
Posts: 43
Joined: 10 Dec 2011, 12:41

Post 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]
Damace
Posts: 58
Joined: 04 Jul 2011, 16:45

Post 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.
hellopaso
Posts: 43
Joined: 10 Dec 2011, 12:41

Post 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?
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

hellopaso wrote:it was connected with the size of SFSObject.
Can you better explain how size was involved?
Paolo Bax
The SmartFoxServer Team
hellopaso
Posts: 43
Joined: 10 Dec 2011, 12:41

Post 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 ;)
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Also I tested your code using nested SFSObjects, using 4000 items each with 3 integers and I don't get any errors.
Lapo
--
gotoAndPlay()
...addicted to flash games
hellopaso
Posts: 43
Joined: 10 Dec 2011, 12:41

Post 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
 
tortenazor
Posts: 6
Joined: 01 Mar 2012, 12:45

Re: The supplied index is out of bounds.

Post 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
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: The supplied index is out of bounds.

Post by Lapo »

Can you at least report the full stack trace of the error?
Lapo
--
gotoAndPlay()
...addicted to flash games
tortenazor
Posts: 6
Joined: 01 Mar 2012, 12:45

Re: The supplied index is out of bounds.

Post 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
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: The supplied index is out of bounds.

Post 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.
Lapo
--
gotoAndPlay()
...addicted to flash games
tortenazor
Posts: 6
Joined: 01 Mar 2012, 12:45

Re: The supplied index is out of bounds.

Post 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
Attachments
server.jpg
(14.74 KiB) Not downloaded yet
Post Reply