Quote:
How were you 'refilling' the vectors?
myVec.push_back();
Quote:Quote:please note: any criticism of typos is unappreciated, as this was just an example and not ACTUAL code
The onus is on you to give an example that reflects the actual code you have problems with, otherwise any advice we give you may prove inaccurate.
I understand this in most cases, but all to often i'll beasking something similar to this and just retyping something general, and people will start commenting that i forgot a semicolon, not ever answering the original question... it's just frustrating to deal with that when i've already checked for typos, and typos (like semicolons, but obviously not variable names) usually come out during compilation, not as access violations.
following are code fragrments from the actual prog... again, it works using iterators, but NOT []:
//maing_pGraphics->CleanupAll(); //empties the vectors as discussed aboveg_pGraphics->AddBackground(IDB_BG);g_pGraphics->AddBackground(IDB_WALL, 0, true, RGB(0, 0, 0));g_pBallSprite = g_pGraphics->AddSprite(IDB_BALL, g_rcPlayfield, 0, 0, BA_BOUNCE, 0, true);// graphic enginevoid GraphicEngine::CleanupAll(){ CleanupSprites(); // work similar to emptying the bitmap vector CleanupBackgrounds(); CleanupForegrounds(); if(!m_vBitmaps.empty()) { vector<Bitmap*>::iterator biBitmap; for (biBitmap = m_vBitmaps.begin(); biBitmap != m_vBitmaps.end(); biBitmap++) { delete (*biBitmap); m_vBitmaps.erase(biBitmap); biBitmap--; } } m_vBitmaps.clear(); }/* used to bevoid GraphicEngine::CleanupAll(){ CleanupSprites(); CleanupBackgrounds(); CleanupForegrounds(); if(!m_vBitmaps.empty()) for (int i = 0; i < m_vBitmaps.size(); ++i) delete m_vBitmaps; m_vBitmaps.clear();}*/...void GraphicEngine::AddSprite(Sprite* pSprite){ // Add a sprite to the sprite vector if (pSprite != NULL) { // See if there are sprites already in the sprite vector if (m_vSprites.size() > 0) { // Find a spot in the sprite vector to insert the sprite by its z-order vector<Sprite*>::iterator siSprite; for (siSprite = m_vSprites.begin(); siSprite != m_vSprites.end(); siSprite++) if (pSprite->GetZOrder() < (*siSprite)->GetZOrder()) { // Insert the sprite into the sprite vector m_vSprites.insert(siSprite, pSprite); return; } } // The sprite's z-order is highest, so add it to the end of the vector m_vSprites.push_back(pSprite); }}...Sprite* GraphicEngine::AddSprite(...){ HDC hDC = GetDC(m_hWindow); if ((hDC != NULL) && (m_hInstance != NULL)) { Bitmap* newBit = new Bitmap(hDC, uiResID, m_hInstance, bTrans, crTransColor); if (newBit != NULL) { m_vBitmaps.push_back(newBit); POINT v = {0, 0}; POINT pos = {xPos, yPos}; Sprite* newSprite = new Sprite(newBit, pos, v, ZOrder, rcBounds, baAction); AddSprite(newSprite); return newSprite; } } return NULL;}// the add background works similarly but with fewer variables
Quote:
What did you do to test whether the vector had really been cleared or not? Did you check size() and capacity()?
doesn't clear() do that reliably? or in which cases wouldn't it?
hopefully that's enough info