|
loading Bitmaps into a vector |
Mark Oates
Member #1,146
March 2001
|
ok here's the code (using OpenLayer):
it's a class that contains all the bmp images in the "graphics/tiles/" directory and puts each one into the "vector<Bitmap> image", giving them each an index number, and allowing you to draw them using the index number. But it doesn't work because when displaying the images, they are all the last image that was loaded. What's going on? -- |
HoHo
Member #4,534
April 2004
|
Have you tried printing out gimp_string in the load() function? __________ |
Mark Oates
Member #1,146
March 2001
|
the gimp_string gets the right address for each image. I also tried slapping in if (!image[image.size()-1]) allegro_message("blurb!"); and the images load without error. It's like they are being overwritten with the wrong Bitmap address or something. -- |
Don Freeman
Member #5,110
October 2004
|
I would try to load them into a dumby BITMAP * first to test they are correct and then add them to the vector. Example:
This should work...thought some of the functions you are using such as the gimp functions, I've never used or seen...so I am guessing at how they work. Also...you may not need to destroy the bitmap pointer, as I can't remeber how allegro handles the memory. I would try it with it first....and if you get an access error, then remove the destroy_bitmap(pBMP); and pBMP = NULL; -- |
HoHo
Member #4,534
April 2004
|
It seems to be correct but as you say there must be a problem somewhere I'll just list some stupid ideas Have you checked the value of image.size()? If everything else fails use a debugger to step through your program __________ |
Don Freeman
Member #5,110
October 2004
|
And if you are using the image.Load(...) function above to load the next image...that is your error! If you are trying: image[image.size()-1].Load(gimp_string.c_str()); then image.size()-1 would be the image you just loaded! Edit: -- |
Mark Oates
Member #1,146
March 2001
|
if I comment out image[image.size()-1].Load(gimp_string.c_str()); then all the images are white. So the idea is that I push_back(*garbage*) then re-load the image with that last line. HoHo: -- |
HoHo
Member #4,534
April 2004
|
Does it happen to be that in Bitmap class you store BITMAP pointers and for some reason they are pointing to the exact same image? Perhaps some static or uninitialized variable causes it. Could you post more source? Bitmap class definition, constructor and Bitmap::Load functions would probably help. __________ |
Mark Oates
Member #1,146
March 2001
|
it's OpenLayer's Bitmap... -- |
Don Freeman
Member #5,110
October 2004
|
Are you loading the images after initializing allegro? You may not know, but even objects that are created before allegro is initialized (if they contain BITMAPs) will cause the BITMAPs to be garbage. Also, I agree that more source will reveal the problem...it looks like there is something somewhere else too that is causing this. Edit: Quote: if (!image[image.size()-1]) allegro_message("blurb!"); This does not neccessarly mean that the image is correct. The way the vector is optimized is that it adds at least 2 to 3 extra spots. The vector may not be growing correctly. -- |
HoHo
Member #4,534
April 2004
|
Quote: it's OpenLayer's Bitmap... heh, I should have thougt of that Quote: This does not neccessarly mean that the image is correct There are two separate things: size and capacity. Usually, when vector resizes itself its capacity increases 50% but its size doesn't. __________ |
|