#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0

    Allegro crashes when running load_bitmap. Why?


    I can not get Allegro to load any BMP images. Here is a section of test code. The picture is in the working directory:

    BITMAP *my_pic;
    my_pic = load_bitmap("kirby.bmp", NULL);

    if(!my_pic)
    {
    allegro_message("ERROR lol");
    return EXIT_FAILURE;
    }

    I always get the error message. Why would the image not be found?

    Allegro does work. I can draw pictures with it.

    Comments on this post

    • jwdonahue disagrees : Not working, as is the case here, and crashing, which is not the case here, are two different things. "Allegro crashes..." is a bad title choice.
  2. #2
  3. Psycho Canadian
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jan 2001
    Location
    Canada
    Posts
    4,846
    Rep Power
    635
    I assume this is in C or C++, I'm moving this thread to that forum you might get a better answer there :).
  4. #3
  5. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    Where is your pallet?

    Code:
    BITMAP *load_bitmap(const char *filename, RGB *pal);
    
    Loads a bitmap from a file. The palette data will be stored in the second parameter, which should be an array of 256 RGB structures. At present this function supports BMP, LBM, PCX, and TGA files, determining the type from the file extension. 
    If the file contains a truecolor image, you must set the video mode or call set_color_conversion() before loading it. In this case, if the destination color depth is 8-bit, the palette will be generated by calling generate_optimized_palette() on the bitmap; otherwise, the returned palette will be generated by calling generate_332_palette(). 
    
    The pal argument may be NULL. In this case, the palette data are simply not returned. Additionally, if the file is a truecolor image and the destination color depth is 8-bit, the color conversion process will use the current palette instead of generating an optimized one. 
    
    Example: 
    
          BITMAP *bmp;
          PALETTE palette;
          ...
          bmp = load_bitmap("image.pcx", palette);
          if (!bmp)
             abort_on_error("Couldn't load image.pcx!");
          ...
          destroy_bitmap(bmp);Return value: Returns a pointer to the bitmap or NULL on error. Remember that you are responsible for destroying the bitmap when you are finished with it to avoid memory leaks.

    Comments on this post

    • jwdonahue disagrees : If you has actually read the docs you copied here, you'd see that the pal argument can be NULL.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    887
    Is kirby.bmp in the same directory where you are testing your program?
    I no longer wish to be associated with this site.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    5
    Rep Power
    0
    Hi. Found out that the problem was that the BMP file was corrupted. That is why it would not load. Thanks for taking a look at my question.

    - Joe

IMN logo majestic logo threadwatch logo seochat tools logo