簡體   English   中英

Visual Studio 2013上的Allegro 4.4.2未處理異常

[英]Allegro 4.4.2 On Visual Studio 2013 Unhandled Exception

我開始在Visual Studio 2013上使用allegro 4.4.2。我在VS上同時安裝了allegro 4.4.2和5.0.10,並開始測試allegro 4.4.2的一些示例。

這是我的代碼:

#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的過程才能使我的PC再次正常工作。 這是該異常的屏幕截圖:

在此處輸入圖片說明

誰能告訴我我做錯了嗎?

謝謝

在這一部分中, botones = load_bmp("bton.bmp", NULL); 您應該在后面添加一些內容,例如:

if( botones == NULL )
    return 0;

為了驗證它是否正確加載,因為load_bmp如果無法正確加載文件,則將返回NULL指針。 調用Pinta_botones ,將調用blit函數,其功能是將源位圖的矩形區域復制到目標位圖。

在調用blit時,源位圖(在這種情況下為botones )在屏幕快照中似乎是NULL指針,這將在嘗試訪問NULL引用時引起問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM