Hello. We have found an infinite loop in ObjectPoolBase and we decided to report it
In function
there is a while loop that starts with this code:
When instantiatedObject was destroyed by any reason and is null, it will be never removed from the collection because execution flow will never reach pool.RemoveFirst().
One way to fix the problem is to remove object before null checking. Also I propose cleaner comment.
In function
C#:
private GameObject ObjectFromPool(PooledObjectKey pooledObjectKey, Vector3 position, Quaternion rotation, Transform parent)
there is a while loop that starts with this code:
C#:
while (pool.Count > 0) {
var instantiatedObject = pool.First.Value;
// The object may be null if it was removed from an additive scene. Keep popping from the pool until the pool has a valid object or is empty.
if (instantiatedObject == null) {
continue;
}
pool.RemoveFirst();
...
When instantiatedObject was destroyed by any reason and is null, it will be never removed from the collection because execution flow will never reach pool.RemoveFirst().
One way to fix the problem is to remove object before null checking. Also I propose cleaner comment.
C#:
while (pool.Count > 0) {
var instantiatedObject = pool.First.Value;
pool.RemoveFirst();
// The object may be null if it was destroyed by any reason (unloading scene, etc.). Keep removing objects from the pool until the pool has a valid object or is empty.
if (instantiatedObject == null) {
continue;
}
...