Page 1 of 1

An item with the same key has already been added. (Pools)

Posted: Tue Mar 01, 2011 12:16 am
by Spankenstein
I create a number of boxes and place them in a pool during my load method:

Code: Select all

box = new Box(position, size, size, size, 1);
Now I take a box from the pool:

Code: Select all

        public void Spawn(Matrix worldTransform)
        {
            isValid = true;

            colourTimer.Reset();
            colourTimer.Start();

            box.WorldTransform *= worldTransform;

            // Force inertia tensor to update
            box.BecomeDynamic(box.Mass);                    // Can change collision group

            box.IsAffectedByGravity = false;

            game.Space.Add(box);
        }
Use it in the Space for a random period and then return it to the pool:

Code: Select all

        public void Kill()
        {
            isValid = false;
        
            colourTimer.Stop();

            // Reset entity (remove all forces)
            box.LinearVelocity = new Vector3();
            box.AngularVelocity = new Vector3();
            box.WorldTransform = Matrix.Identity;

            game.Space.Remove(box);
        }
The next time I take the same box from the pool and it is involved with a collision, the following error message occurs during the space.Update method:
An item with the same key has already been added.
How can this be avoided with pooled entities?

Re: An item with the same key has already been added. (Pool

Posted: Tue Mar 01, 2011 12:29 am
by Norbo
It's probably just a bug with some bookkeeping related to collision pairs. I'll see if I can reproduce it soon.

Re: An item with the same key has already been added. (Pool

Posted: Wed Mar 02, 2011 8:30 am
by Norbo
I did some testing and encountered/fixed a variety of simulation island-related bugs, but no "An item with the same key has already been added" yet.

I'll be uploading a new beta momentarily. I don't remember changing anything that would fix that exception, but it's worth a shot just in case. If (when) the problem still occurs, the full stacktrace would help me narrow down the causes. Any additional context you could provide would help too.

Re: An item with the same key has already been added. (Pool

Posted: Wed Mar 02, 2011 10:12 pm
by Spankenstein
The latest BETA (23) has fixed the problem :)