curiously i have the exact same problem at the moment and i've been following the thread
that is interesting. like suggested im checking if i'm in world
IsInWorld returns false, but the objectmanager.pulse() method is still called. i just put a 1 second sleep in there and the game starts "lagging" ...Code:if (ObjectManager.IsInWorld) ObjectManager.Pulse();
Last edited by YetiHunter; 03-01-2010 at 02:43 PM.
do something like that, iterate it backwards and use RemoveAt and it shouldn't throw the InvalidOperationException.
That's just a poor example don't think it will work properly but you get the idea (do it backwards)
Code:private static void RemoveInvalidEntries() { var guids = (from o in RealObjects where !o.Value.IsValid select o.Key).ToArray(); for(int i = guids.Length - 1; i >= 0; i--) { RealObjects.RemoveAt(i); } }
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - Martin Golding
"I cried a little earlier when I had to poop" - Sku
i made a litte bit of progress. i was able to trace the problem to the get object by guid function. i get the guid, but the getObjByGuid funktion returns 0. the address is correct and if i try to filter for a type (for example players, so i use 4 as filter) it crashes. TOM_RUS mentioned something that the filter isn't actually a int if i understood correct but a pointer to an int. I tried it, but no success and no crashing. am i doing it wrong or is the pointerapproach wrong?
No.
If ure gonna modify a collection while iterating it you need to do it backwards otherwise you would change the size of it and cause the "System.InvalidOperationException was unhandled
Message="Collection was modified; enumeration operation may not execute."excetion to get thrown,
Code:var guids = (from o in ObjectManager.ObjectList where !o.IsValid select o).ToArray(); for (int i = ObjectManager.ObjectList.Count - 1; i >= 0; i--) { if(guids.Contains(ObjectManager.ObjectList[i])) ObjectManager.ObjectList.RemoveAt(i); }
Erm... you guys DO know about List<T>.RemoveAll, right?
List(T).RemoveAll Method (System.Collections.Generic)
This neatly bypasses all of the "modified collection" issues by simply removing all items that match a predicate (o => !o.IsValid, in this case).
Otherwise, to sidestep the modified collection issue, I usually just clone the input collection as a source for invalids (in other words: I have a list, Foo. I clone it and make Foo2. Then, for each "bad" item in Foo2, I remove the corresponding item from Foo). For small lists -- like the list of "bad" objects in WoW -- this is perfectly reasonable.
Still, RemoveAll is better.
Don't believe everything you think.
Now I didn't read the thread; Just this last page..
But why would anyone try iterating a list and try removing everything themselves? Do what amadmonk said, List.RemoveAll with a predicate that you want removed.
i'm sorry to interrupt the discussion but does anyone know why my getObjByGuid function call is not working properly?
ObjectList isn't List. It's Dictionary and doesn't have RemoveAll implementation.
I already posted solution on previous page: http://www.mmowned.com/forums/wow-me...ml#post1820129
That means that EnumVisibleObjects also doesn't work properly. Try to dig it.
Last edited by TOM_RUS; 03-03-2010 at 03:09 AM.