Oh why does the following code crash after all is done? And how does the copier in vector.push_back work while the commented out line looses the image in bms (after you uncomment it...)?
Code:
#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
class foo
{
public:
~foo()
{
for(size_t i = 0; i < bms.size(); i++)
destroy_bitmap(bms[i]);
bms.clear();
textout(screen, font, "Now press that key...", 0, 0, 255);
readkey();
}
PALLETE pal;
vector <BITMAP*> bms;
void add(char *fname)
{
BITMAP *temp = load_bitmap("foo.pcx", pal);
if(!temp)
exit(1);
bms.push_back(temp);
// destroy_bitmap(temp);
}
};
void init();
int main()
{
init();
foo bar;
bar.add("foo.pcx");
set_pallete(bar.pal);
blit(bar.bms[0], screen, 0, 0, 99, 99, bar.bms[0]->w, bar.bms[0]->h);
return 0;
}
void init()
{
allegro_init();
install_keyboard();
set_color_depth(16);
if (set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0) != 0)
{
allegro_exit();
printf("Error setting graphics mode\n%s\n\n", allegro_error);
exit(1);
}
set_color_conversion(COLORCONV_TOTAL);
}