Problems with PooledEnumerable
Hope i opened the thread in the right place.
I think there's a problem with PooledEnumerable Free function (not only with it but the chain of calls it creates through the enumerator).
Let pretend that we called GetObjectInRange function, we have:
PooledEnumerable with m_Enumerator = ObjectEnumerator (the one below), m_Depth = 1;
ObjectEnumerator with m_Enumerable = PooledEnumerable (the one above), m_Enumerator = SectorEnumerator (the one below), m_Map = whatever but not null
SectorEnumerator with m_Enumerable = null, m_Map = whatever (the same of ObjectEnumerator).
You use foreach to loop through PooledEnumerable and when you exit from the foreach the Dispose function of PooledEnumerable is called, and this will call Free fcuntion that is:
m_Enumerator is not null so it calls the ObjectEnumerator Free function that is:
m_Map is not null so it continues, m_Enumerator is not null so it calls the SectorEnumerator Free function that is:
m_Enumerable is null so we can return back through the calls.
Ok now we are in the previous call, where m_Enumerator (of ObjectEnumerator) is nulled.
Then since m_Enumerable is not null (PooledEnumerable) its free function is called, so we are again on the top Free function, where m_Enumerator is not null
and in m_InstancePool the PooledEnumerable is enqued again and m_Enumerator Free function is called again (the ObjectEnumerator one).
So now we are in the middle Free function, m_Map is null so it istantly return to the top Free function where m_Enumerator is nulled and m_Depth decreased to 0.
But we didn't finish because the top Free function was called by the middle one previously, and after that it goes to the top one, setting again m_Enumerator to null
and decrease m_Depth to -1.
This is Ok!?!?
And why when you use IPooledEnumerable you have to again call eable.Free()?
Hope you managed to follow me...
Hope i opened the thread in the right place.
I think there's a problem with PooledEnumerable Free function (not only with it but the chain of calls it creates through the enumerator).
Let pretend that we called GetObjectInRange function, we have:
PooledEnumerable with m_Enumerator = ObjectEnumerator (the one below), m_Depth = 1;
ObjectEnumerator with m_Enumerable = PooledEnumerable (the one above), m_Enumerator = SectorEnumerator (the one below), m_Map = whatever but not null
SectorEnumerator with m_Enumerable = null, m_Map = whatever (the same of ObjectEnumerator).
You use foreach to loop through PooledEnumerable and when you exit from the foreach the Dispose function of PooledEnumerable is called, and this will call Free fcuntion that is:
Code:
public void Free()
{
if ( m_Enumerator != null )
{
m_InstancePool.Enqueue( this );
m_Enumerator.Free();
m_Enumerator = null;
--m_Depth;
}
}
m_Enumerator is not null so it calls the ObjectEnumerator Free function that is:
Code:
public void Free()
{
if ( m_Map == null )
return;
m_InstancePool.Enqueue( this );
m_Map = null;
if ( m_Enumerator != null )
{
m_Enumerator.Free();
m_Enumerator = null;
}
if ( m_Enumerable != null )
m_Enumerable.Free();
}
m_Map is not null so it continues, m_Enumerator is not null so it calls the SectorEnumerator Free function that is:
Code:
public void Free()
{
if ( m_Map == null )
return;
m_InstancePool.Enqueue( this );
m_Map = null;
if ( m_Enumerable != null )
m_Enumerable.Free();
}
m_Enumerable is null so we can return back through the calls.
Ok now we are in the previous call, where m_Enumerator (of ObjectEnumerator) is nulled.
Then since m_Enumerable is not null (PooledEnumerable) its free function is called, so we are again on the top Free function, where m_Enumerator is not null
and in m_InstancePool the PooledEnumerable is enqued again and m_Enumerator Free function is called again (the ObjectEnumerator one).
So now we are in the middle Free function, m_Map is null so it istantly return to the top Free function where m_Enumerator is nulled and m_Depth decreased to 0.
But we didn't finish because the top Free function was called by the middle one previously, and after that it goes to the top one, setting again m_Enumerator to null
and decrease m_Depth to -1.
This is Ok!?!?
And why when you use IPooledEnumerable you have to again call eable.Free()?
Hope you managed to follow me...