mardi 21 juin 2016

Allegro on Dev-C++ or CodeBlocks Unhandled Exception

I´m starting to use allegro on Dev-C++. I installed both allegro 4.4.2 and 5.0.10 on Dev-C++ and started testing some examples of allegro

This is my code:

#include <allegro.h>
#define ALLEGRO_STATICLINK
#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 );
};

// solo para boton izquierdo
void cambiaccion(){
     if (mouse_x > 0 && mouse_x < 32 &&
         mouse_y > 0 && mouse_y < 32){
          rect( buffer, 1,1,30,30, 0x666666 );
          if ( mouse_b&1 ) accion = 1 ;
     }
     if (mouse_x > 32 && mouse_x < 64 &&
         mouse_y > 0 && mouse_y < 32){
          rect( buffer, 33,1,62,30, 0x666666 );
          if ( mouse_b&1 ) accion = 2;
     }
     if (mouse_x > 0 && mouse_x < 32 &&
         mouse_y > 32 && mouse_y < 64){
          rect( buffer, 1,33,30,62, 0x666666 );
          if ( mouse_b&1 ) accion = 3;
     }
     if (mouse_x > 32 && mouse_x < 64 &&
         mouse_y > 32 && mouse_y < 64){
          rect( buffer, 33,33,62,62, 0x666666 );
          if ( mouse_b&1 ) accion = 4;
     }
};


void realizaccion(){
     switch(accion){
     case 1:
             clear_to_color(dibujo, 0xFFFFFF);
             break;
     case 2:
             putpixel( dibujo, mouse_x, mouse_y, 0xffffff);
             break;
     case 3:
          //  rellenamos con un color
            break;
     case 4:
           putpixel( dibujo, mouse_x, mouse_y, 0x000000);
           break;

     };
};



void Pinta_botones(){
     blit( botones, buffer, 0,0, 0,0,64, 64);
};


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



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


 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);
 if( botones == NULL )
    return 0;

    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, Dev-C++ 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 Dev-C++ in order to get my pc to work normally again. Here´s a screenshot of the exception:

enter link description here

Can anyone tell what I´m doing wrong?

Thank you

Aucun commentaire:

Enregistrer un commentaire