Excalibur
Excalibur copied to clipboard
Bug: pool creating objects twice for first call
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:
@keasy9 Thanks for the issue, this certainly feels like a bug
@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
RentalPool returns an object to the pool