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

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

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

Post 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?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

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

Post by Norbo »

It's probably just a bug with some bookkeeping related to collision pairs. I'll see if I can reproduce it soon.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

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

Post 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.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

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

Post by Spankenstein »

The latest BETA (23) has fixed the problem :)
Post Reply