Excalibur icon indicating copy to clipboard operation
Excalibur copied to clipboard

Bug: pool creating objects twice for first call

Open keasy9 opened this issue 2 months ago • 2 comments

When I making pool and getting object from it first time, object constructor called twice.

Minimal reproducing example:

import {Actor, Pool} from 'excalibur';

class TestActor extends Actor {
    constructor() {
        super();
        console.log('TestActor created');
    }
}

const pool = new Pool(
    () => {
        console.log('Creating new actor');
        return new TestActor();
    },
    (actor) => {
        console.log('Recycling actor');
        return actor;
    }
);

console.log('First get:');
const a1 = pool.get();
pool.done(a1);

console.log('Second get:');
const a2 = pool.get();

console.log(pool.objects.length);

and console: Image

keasy9 avatar Oct 25 '25 07:10 keasy9

@keasy9 Thanks for the issue, this certainly feels like a bug

eonarheim avatar Oct 27 '25 13:10 eonarheim

@keasy9 Okay this got me too, but we have a "feature" that unhooks things from the pool if passed to done() so the pool creates a new one to make up for it. This is why we see to calls in this case.

.done() assumes you're done with all instances you've retrieved

Image

RentalPool returns an object to the pool

Image

eonarheim avatar Oct 27 '25 13:10 eonarheim