Archived

This topic is now archived and is closed to further replies.

BeanDog

What does stl::List<>::size() return mean?

Recommended Posts

Here''s some code that fails: int iSpriteCount = iList->size(); for(SPRITE_LIST::iterator iSprite = iList->begin(); iSprite != iList->end(); iList++) { iSpriteOn++; ASSERT(iSpriteOn < iSpriteCount); } How could that assert possibly fail? I checked, and the list only has a few thousand entries. ~BenDilts( void );

Share this post


Link to post
Share on other sites
are you initializing iSpriteOn to 0 anywhere?


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
Here''s the more fully-written out code, with < changed to <=. It still fails on the same line.

list::iterator iTex = m_lMassRenderingTextures.begin();
list::iterator iList = m_lMassRenderingSprites.begin();

ASSERT(m_lMassRenderingSprites.size() == m_lMassRenderingTextures.size());
for(;iTex != m_lMassRenderingTextures.end(); iTex++)
{
hr = dev->SetTexture(0, **iTex);
if(FAILED(hr))
return(FALSE);

int iSpriteCount = iList->size();

B3D_SPRITEVTX *vtx = new B3D_SPRITEVTX[iSpriteCount*4];
B3D_SPRITEVTX *vtxTemp = vtx;

int iSpriteOn = 0;
for(SPRITE_LIST::iterator iSprite = iList->begin(); iSprite != iList->end(); iList++)
{
vtxTemp[0] = (*iSprite)->m_Vtx[0];
vtxTemp[1] = (*iSprite)->m_Vtx[1];
vtxTemp[2] = (*iSprite)->m_Vtx[2];
vtxTemp[3] = (*iSprite)->m_Vtx[3];
vtxTemp += 4;
iSpriteOn++;
ASSERT(iSpriteOn <= iSpriteCount);
}

hr = dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2*iSpriteCount, vtx, sizeof(*vtx));

delete [] vtx;

if(FAILED(hr))
return(FALSE);

iList++;
}


~BenDilts( void );

Share this post


Link to post
Share on other sites
If iList is an iterator, why (how?) are you getting the begin(), end(), and size() of it?

What am I missing here?

[edit: what is wrong with my english today...geesh]

[edited by - scaught on January 29, 2003 9:58:02 PM]

Share this post


Link to post
Share on other sites
SPRITE_LIST::iterator iSprite = iList->begin(); iSprite != iList->end(); iList++

I think you mean "iSprite++". Ta da!


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
oh, and what you really mean is "++iSprite", since that''s more efficient with iterators (no need to create a temporary object).


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites