Allegro error checking system

This is a discussion on Allegro error checking system within the Game Programming forums, part of the General Programming Boards category; I am making an Allegro game, and I think it would be good to have a nice error checking system ...

  1. #1
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326

    Allegro error checking system

    I am making an Allegro game, and I think it would be good to have a nice error checking system laid out before I start coding, this is how I usualy do it, I don't think it is good enough, what kind of systems do you use with your Allegro programs?

    Code:
    /*******************/
    /* V-Ball          */
    /* Undefined Games */
    /*******************/
    
    #include <allegro.h>
    
    
      FILE   *fp     = NULL;
      BITMAP *buffer = NULL;
    
      int  setup();
      void shutdown();
    
    int main()
    {
      fp = fopen("log.txt", "w");
      if(fp == NULL)
      {
        printf("Could not open log file, exiting...");
        return 0;
      }
    
      fprintf(fp, "Starting program execution\n");
    
      if(setup() != 0)
      {
        fprintf(fp, "Setup failed\n");
      }
      else
      {
        while(!key[KEY_ESC])
          ;
      }
    
      shutdown();
      return 0;
    }
    END_OF_MAIN();
    
    /*******************/
    
    int setup()
    {
      allegro_init();
    
      if(install_keyboard() != 0)
      {
        fprintf(fp, "Could not install keyboard\n");
        return 1;
      }
    
      buffer = create_bitmap(640, 480);
      if(buffer == NULL)
      {
        fprintf(fp, "Could not create buffer\n");
        return 1;
      }
    
      set_color_depth(32);
      if(set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0) != 0)
      {
        fprintf(fp, "Could not set graphics mode\n");
        return 1;
      }
    
      return 0;
    }
    
    /*******************/
    
    void shutdown()
    {
      destroy_bitmap(buffer);
    
      fprintf(fp, "Ending program execution\n");
      fclose(fp);
    }
    
    /*******************/

  2. #2
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    That seems good enough to me. In fact I don't go nearly as far as you do. About the only thing different I do is if the color depth can't be set to 32 I try to set it to a lower value.

  3. #3
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    I was thinking of creating an enumerated constant with different errors, then having a function log_error() that will print more information about it.

    Code:
    enum errors { UNABLE_SET_GRAPHICS, UNABLE_LOAD_SPRITE, ... };
    
    if(error)
    {
      log_error(UNABLE_LOAD_SPRITE);
    }
    
    log_error(int e)
    {
      switch(e)
      {
        case UNABLE_LOAD_SPRITE:
          fprintf(fp, "Unable to load the sprite, sprite.bmp\n");
          break;
        default:
          break;
      }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 06:56 PM
  2. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  3. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 04:35 PM
  4. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 06:12 AM
  5. Problem Reporting System. Need Advide!
    By brunomiranda in forum Tech Board
    Replies: 9
    Last Post: 09-25-2003, 09:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21