Allegro 4.4.2 On Visual Studio 2013 Unhandled Exception

158 views Asked by At

I´m starting to use allegro 4.4.2 on Visual Studio 2013. I installed both allegro 4.4.2 and 5.0.10 on VS and started testing some examples of allegro 4.4.2

This is my code:

#include <allegro.h>
#define ANCHO 640
#define ALTO  480

int soltado = 1;
int accion = 4;
BITMAP *buffer;
BITMAP *dibujo;
BITMAP *botones;

bool Sobre_boton(){
    return (mouse_x >0 && mouse_x < 64 &&
        mouse_y >0 && mouse_y < 64);
};
void cambiaccion(){};

void realizaccion(){};
void Boton_izquierdo(){
    if (Sobre_boton()){
        cambiaccion();
    }
    else{
        realizaccion();
    }
};



void Pinta_cursor(){
    circle(buffer, mouse_x, mouse_y, 2, 0x000000);
    putpixel(buffer, mouse_x, mouse_y, 0x000000);
};
void Pinta_botones(){
    blit(botones, buffer, 0, 0, 0, 0, 64, 64);
};

int main()
{
    allegro_init();
    install_keyboard();
    install_mouse();

    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, ANCHO, ALTO, 0, 0);

    buffer = create_bitmap(ANCHO, ALTO);
    dibujo = create_bitmap(ANCHO, ALTO);

    botones = load_bmp("bton.bmp", NULL);

    clear_to_color(buffer, 0xFFFFFF);
    clear_to_color(dibujo, 0xFFFFFF);

    while (!key[KEY_ESC]){
        blit(dibujo, buffer, 0, 0, 0, 0, ANCHO, ALTO);
        Pinta_botones();

        //pulsa boton izquierdo
        if (mouse_b & 1){
            Boton_izquierdo();
        }
        else{
            soltado = 1;
        }

        Pinta_cursor();
        blit(buffer, screen, 0, 0, 0, 0, ANCHO, ALTO);
    }

    destroy_bitmap(botones);
    destroy_bitmap(dibujo);
    destroy_bitmap(buffer);
    return 0;
}
END_OF_MAIN();

When I run the project, VS starts lagging horribly, to the point I have to wait like 7 seconds to see my mouse cursor move. I have to terminate the process of VS in order to get my pc to work normally again. Here´s a screenshot of the exception:

enter image description here

Can anyone tell what I´m doing wrong?

Thank you

1

There are 1 answers

1
Ediac On BEST ANSWER

In this part botones = load_bmp("bton.bmp", NULL); you should add something after, like:

if( botones == NULL )
    return 0;

To validate whether it was loaded properly or not, as load_bmp will return a NULL pointer if it fails to correctly load the file. When Pinta_botones is called, the function blit is called, whose functionality is to copy a rectangular area of the source bitmap to the destination bitmap.

The source bitmap, in this case botones appears to be a NULL pointer in the screenshot when blit is called, which will cause problems when trying to access a NULL reference.