2015-06-20 54 views
1

我開始在Visual Studio 2013上使用allegro 4.4.2。我在VS上安裝了兩個allegro 4.4.2和5.0.10,並開始測試allegro 4.4的一些示例。 2Allegro 4.4.2在Visual Studio 2013上未處理的異常

這是我的代碼:

#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(); 

當我運行該項目,啓動VS滯後可怕的,要我必須等待像7秒看我的鼠標光標移動的點。我必須終止VS的過程才能讓我的電腦再次正常工作。 Here's異常的截圖:

enter image description here

誰能告訴什麼I'm做錯了什麼?

謝謝

回答

1

在這一部分botones = load_bmp("bton.bmp", NULL);你應該後添加的東西,如:

if(botones == NULL) 
    return 0; 

爲了驗證它是否被正確或沒有加載,因爲如果它不能load_bmp將返回一個NULL指針正確加載文件。當調用Pinta_botones時,函數blit被調用,其功能是將源位圖的矩形區域複製到目標位圖。

源位圖,在這種情況下botones似乎是當blit稱爲截圖,試圖訪問一個NULL參考時,這將導致問題NULL指針。

+0

非常感謝你解決了這個問題。你知道VS發生這種情況時爲什麼會滯後嗎? –