Quote:Original post by chollida1
Quote:Original post by Morbo
This isn't a problem with your array, it's a problem with RECTs. IIRC, Windows RECTs don't like being copied/assigned. It would work if you did this instead:
*** Source Snippet Removed ***
Because then you're not copying the RECT itself, just the reference.
But, aside from being bad OOP practice, I'd just avoid using RECT entirely and use your own structure. I try to avoid Windows structures in general, though...
I've never heard of this, RECT is just a struct with 4 longs, the default shallow assingment operator should be able to handle this. I think its more likely what I mentioned earlier that the 0 row and column aren't being initialized.
Cheers
Chris
Exactly! chollida1 is correct.
Sorry Morbo, but what you said is merely superstition/heresay or something. Copying RECTs works absolutely fine. His code wouldn't crash like that anyway.
The problem is that he initialises his array using for loops like this:
for(int i=1; i<=_iNumBrickRows; i++)
but accesses them with for loops like this:
for(int i=0; i<_iNumBrickRows; i++)
(The second one is correct) It goes from 0 to _iNumBrickRows-1. The first loop has to be the same.
The first bit of code will need to change slightly to accomodate the shift in starting values...
for(int i=0; i<_iNumBrickRows; i++) { for(int j=0; j<_iNumBrickCols; j++) { _pBrickSprites[j] = new Sprite(_pBrickBitmap); _pBrickSprites[j]->SetPosition(_pGame->GetWidth()*(j+1)/(_iNumBrickCols+1) - _pBrickBitmap->GetWidth()/2, _iVerticalBrickSpacing*(i+1) + _pBrickBitmap->GetHeight()*i); _pGame->AddSprite(_pBrickSprites[j]); } }