【问题标题】:Allegro 4.4.2 On Visual Studio 2013 Unhandled ExceptionAllegro 4.4.2 在 Visual Studio 2013 上未处理的异常
【发布时间】:2015-06-20 05:28:54
【问题描述】:

我开始在 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 的进程才能让我的电脑再次正常工作。这是异常的屏幕截图:

谁能告诉我我做错了什么?

谢谢

【问题讨论】:

    标签: c++ allegro


    【解决方案1】:

    在这部分botones = load_bmp("bton.bmp", NULL); 后面你应该添加一些东西,比如:

    if( botones == NULL )
        return 0;
    

    为了验证它是否被正确加载,因为load_bmp如果未能正确加载文件,将返回一个NULL指针。当Pinta_botones被调用时,函数blit被调用,其功能是将源位图的一个矩形区域复制到目标位图。

    源位图,在这种情况下,botones 在调用blit 时在屏幕截图中显示为NULL 指针,这将在尝试访问NULL 引用时出现问题。

    【讨论】:

    • 非常感谢这解决了这个问题。你知道为什么发生这种情况时 VS 会滞后这么多吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多