The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

IndexOutOfRangeException: Array index is out of range.

2015-01-19 14:43:32

Hello all, I overrided the LeaveRoom function of vikingdemo in PUN to test my server, but when i click LeaveRoom button in the game ,a error show up as the title. Here is my code:

the details of error:

At the beginning,i thought the data is overflow,but i just store a string in dictionary still have the same problem. I dont have any idea to fix this. :( Please help me ,thxs. :)


2015-01-19 15:04:04

I can't check this at the moment but will try this week. I think it's a bug that's fixed in PUN 1.50.3 (the main asset in the Asset Store). The Viking Demo is a bit older and maybe has a bug with serialization (which you see). Please try this in the latest PUN package, too.

In general, OpLeave is not really built to include state or anything custom. I don't think your dictionary will arrive at the other clients.

2015-01-19 15:42:55

Thank you for your quick reply ,Tobias.You are right,the dictionary can't even arrive my sever. So,as you said "In general, OpLeave is not really built to include state or anything custom." How can I handle leave Operation to save the state of player,use a OpCustom by self or something other?

2015-01-20 09:01:27

In Turnbased, we do the following: Anything that's relevant for state has to be a buffered event or a Custom Property. Those things are in the server anyways and when everyone left, we store this as state. When this game gets re-joined (by name, by a player who was in that game before), then we can either find the game in memory or load it.

If you put the state in OpLeave you will loose it when a client crashed or loses connection suddenly without calling OpLeave.

2015-01-21 05:01:58

Thank you Tobias,I will do what you said.BTW,I downloaded the last PUN and fixed the problem.

2015-01-23 16:46:25

Super. Thanks for letting us know!

Back to top