Thread: allegro causing a crash

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    129

    allegro causing a crash

    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);
    }

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    look around for a memory allocation problem, though i can't see one right away(you know your code most likely better than i) a crash after exit is usually cause by overwriting memory somewhere in the program.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Oh why does the following code crash after all is done?
    Doesn't Allegro require you to specify END_MAIN or something like that after the closing brace for main?

    -Prelude
    My best code is written with the delete key.

  4. #4
    muttski
    Guest
    END_OF_MAIN(); if your doing it in widnows, in dow it dont matter.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    i'm not an expert on CLASSES but

    why do you use a destructor for the class
    or is it a function but must you not declare the function firts

    ///////////////////////////////////////////
    class foo
    {
    public:
    ~foo() //
    ///////////////////////////////////////////

  6. #6
    bobish
    Guest
    did u remember to call allegro_exit() before ending the game? also why does the program not loop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf causing a crash
    By dougwilliams in forum C Programming
    Replies: 6
    Last Post: 11-18-2007, 04:52 PM
  2. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  3. what is causing this seemingly simple app to crash?
    By Shadow12345 in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 08:36 PM
  4. double buffering for allegro
    By Leeman_s in forum C++ Programming
    Replies: 6
    Last Post: 09-12-2002, 02:45 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM