Jump to content
  • Advertisement
Sign in to follow this  
Kenster

[.net] Any idea? Problem.

This topic is 3654 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

List<Entity> list = new List<Entity>(); foreach (WorldRegion zone in SurroundRegions) { List<Entity> enti = new List<Entity>((IEnumerable<Entity>)zone); foreach (Entity e in enti) { list.Add(e); } } return list; Above is my code. Its used in an MMORPG as the KnownList. Wanted to know if anyone know why in line > List<Entity> enti = new List<Entity>((IEnumerable<Entity>)zone); Zone is modified during the execution. Now, I tried using a lock on Zone, but it still happens. The error is, "Destination array was not long enough. Check destIndex and length, and the array's lower bounds." Anyone have this occured with them before? Thanks! Ken

Share this post


Link to post
Share on other sites
Advertisement
This statement concerns me: Zone is modified during the execution.

Why is zone being modified while being enumerated through? Is something going on in the WorldRegion.GetEnumerator method that is modifying the list? That shouldn't happen.

Have you tried replacing the constructor call with a call to AddRange like:

List<Entity> enti = new List<Entity>();
enti.AddRange(zone);

Share this post


Link to post
Share on other sites
I am not sure. It doesnt happen often, but it does happen. Not sure what condition is causing it, weather the system is lagging or not, I am unsure. The code works like 98% of the time, but is causing a crash sometimes, and I don't know if I can find a way to not it not crash.

Share this post


Link to post
Share on other sites
Yes there is. I am afraid to lock this though, because every .5 this code is ran. If I lock it, I would get backed up with code unable to run?

Share this post


Link to post
Share on other sites
Quote:
Original post by Kenster

Zone is modified during the execution. Now, I tried using a lock on Zone, but it still happens.

Yes there is. I am afraid to lock this though, because every .5 this code is ran. If I lock it, I would get backed up with code unable to run?
Ken


If you don't lock it every where it is modified then it isn't locked. .5 what seconds? days? years? If you lock it there will be delays in accessing it yes, How long does this thread take? if it can update a zone in .1 seconds and you run it every .5 seconds then you got time to spare. Could it skip the zone if it can't acquire the lock and come back to it later?

Share this post


Link to post
Share on other sites
Its every .5 Seconds. It really can't skip as its access by every player in game, every .5 seconds for each zone. Not really sure how to have a KnownList for each Region without grabbing an up to date list every .5 seconds. Been looking at other MMOs tho.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!