|
My vector has lost it's Bitmaps! |
Taiko Keiji
Member #8,307
February 2007
|
I have a small question about vectors. I recently started using them but i'm having some trouble. I have a Sprite class and I made a vector of these sprites vector<Sprite> Sprites; but that's not the problem, the vector works fine. It's when I make a new sprite and add it into the vector for some reason the Bitmap data from the sprite is lost, or something. I was using a for loop to draw the sprites for(int i;i<Sprites.size();i++) { masked_blit(Sprites.at(i).image,buffer,spos,sypos,x,y,16,20); }
but like I said. when I do this it doesn't draw the sprite. for(int i;i<Sprites.size();i++) { pSprite=Sprites.at(i); masked_blit(pSprite.image,buffer,spos,sypos,x,y,16,20); } but that doesn't work either. Life could be better, machines could program themselves. Taiko Keiji- |
X-G
Member #856
December 2000
|
Let me guess; your Sprite class does destroy_bitmap in its destructor. Either don't do that, or implement complete copy semantics, or store pointers to sprites instead of sprites. -- |
Archon
Member #4,195
January 2004
|
If the bitmap was messed up, wouldn't it crash the program? |
Taiko Keiji
Member #8,307
February 2007
|
Ok, first. My destructor doesn't destroy anything. It may just be that I'm having the program draw the bitmap wrong or something because if it didn't load the bitmap i would expect it to crash aswell. I have no idea other than that. Life could be better, machines could program themselves. Taiko Keiji- |
Indeterminatus
Member #737
November 2000
|
Quote: for(int i;i<Sprites.size();i++) You're using variable i that is not initialized. Bad thing! _______________________________ |
X-G
Member #856
December 2000
|
Then show the Sprite class. -- |
GullRaDriel
Member #3,861
September 2003
|
I think Indeterminatus is somewhat right. You should use int for( int i=0; And X-G is right too. Show us the class. "Code is like shit - it only smells if it is not yours" |
Taiko Keiji
Member #8,307
February 2007
|
What do you mean I isn't initialized? Life could be better, machines could program themselves. Taiko Keiji- |
X-G
Member #856
December 2000
|
... exactly what he said. You declare int i in the for loop, but you never initialize it to 0. Also, you're not listening, because you didn't post your Sprite class. -- |
Taiko Keiji
Member #8,307
February 2007
|
I initialized i, don't know how I forgot.
Life could be better, machines could program themselves. Taiko Keiji- |
HoHo
Member #4,534
April 2004
|
Actually the contents of ~Sprite() and Sprite() are the things that matter anything. Function names don't say much of what is going on in the functions themselves. __________ |
Onewing
Member #6,152
August 2005
|
Quote: I initialized i, don't know how I forgot.
for(int i;i<Sprites.size();i++) ------------ |
Taiko Keiji
Member #8,307
February 2007
|
I got it figured out. Thanks for trying guys. I cant particularly say what it was but I think it has to do with the fact that I didn't initialize i. Life could be better, machines could program themselves. Taiko Keiji- |
Tobias Dammers
Member #2,604
August 2002
|
Quote: I got it figured out. (...) I cant particularly say what it was but I think it has to do with the fact that I didn't initialize i. That is a rather nasty contradiction you have there... --- |
BAF
Member #2,981
December 2002
|
Quote: for(int i;i<Sprites.size();i++) Shouldn't that be: for(Vector<Sprite>::iterator = Sprites.begin(); i != Sprites.end(); i++) or something like that? (Not sure if that begin/end is correct because I haven't used C++ STL in a while, I'm still in C#/.net generic mode). |
|