Allegro 程序触发断点?

发布于 2024-12-12 21:32:09 字数 2041 浏览 0 评论 0原文

所以我正在学习精灵编程,我们正在使用 allegro。当我运行示例程序之一时,我收到消息:rotatesprite.exe 已触发断点。这是在视觉工作室。我无法让 allegro 在 Visual Studio

示例程序之外工作:

 #include <allegro.h>

 #define WHITE makecol(255,255,255)

int main(void)
{
int x, y;
float angle = 0;
BITMAP *tank;

//initialize program
allegro_init();
install_keyboard();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
textout_ex(screen,font,"Rotate: LEFT / RIGHT arrow keys",
    0,0,WHITE,0);

//load tank sprite
tank = load_bitmap("C:\Users\Jason\Desktop\module7\tank.bmp", NULL);

//calculate center of screen
//x = SCREEN_W/2 - tank->w/2;
//y = SCREEN_H/2 - tank->h/2;
x=SCREEN_W/2;
y=SCREEN_H/2;

//draw tank at starting location
rotate_sprite(screen, tank, x, y, 0);

//main loop
while(!key[KEY_ESC])
{
    //wait for keypress
    if (keypressed())
    {
        //left arrow rotates left
        if (key[KEY_LEFT])
        {
            angle -= 0.1;
            if (angle < 0) angle = 256;
            rotate_sprite(screen, tank, x, y, itofix(angle));
        }

        //right arrow rotates right
        if (key[KEY_RIGHT])
        {
            angle += 0.1;
            if (angle > 256) angle = 0;
            rotate_sprite(screen, tank, x, y, itofix(angle));
        }

        //display angle
        textprintf_ex(screen, font, 0, 10, WHITE, 0,
            "Angle = %f", angle);
    }
}
allegro_exit();
return 0;
}
END_OF_MAIN()

触发断点的程序是:磁盘上的 crt0msg.c。 代码片段:

         #ifdef _DEBUG
        /*
         * Report error.
         *
         * If _CRT_ERROR has _CRTDBG_REPORT_WNDW on, and user chooses
         * "Retry", call the debugger.
         *
         * Otherwise, continue execution.
         *
         */

         if (rterrnum!=_RT_CRNL&&rterrnum!=_RT_BANNER&&rterrnum!=_RT_CRT_NOTINIT)
        {
            if (1 == _CrtDbgReport(_CRT_ERROR, NULL, 0, NULL,rterrs[tblindx].rterrtxt))
                _CrtDbgBreak();
        }
        #endif  /* _DEBUG */

So I'm learning about sprite programming and we're using allegro. When I run one of the sample programs I get the message: rotatesprite.exe has triggered a breakpoint. This was in visual studio. I can't get allegro to work outside of visual studio

sample program:

 #include <allegro.h>

 #define WHITE makecol(255,255,255)

int main(void)
{
int x, y;
float angle = 0;
BITMAP *tank;

//initialize program
allegro_init();
install_keyboard();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
textout_ex(screen,font,"Rotate: LEFT / RIGHT arrow keys",
    0,0,WHITE,0);

//load tank sprite
tank = load_bitmap("C:\Users\Jason\Desktop\module7\tank.bmp", NULL);

//calculate center of screen
//x = SCREEN_W/2 - tank->w/2;
//y = SCREEN_H/2 - tank->h/2;
x=SCREEN_W/2;
y=SCREEN_H/2;

//draw tank at starting location
rotate_sprite(screen, tank, x, y, 0);

//main loop
while(!key[KEY_ESC])
{
    //wait for keypress
    if (keypressed())
    {
        //left arrow rotates left
        if (key[KEY_LEFT])
        {
            angle -= 0.1;
            if (angle < 0) angle = 256;
            rotate_sprite(screen, tank, x, y, itofix(angle));
        }

        //right arrow rotates right
        if (key[KEY_RIGHT])
        {
            angle += 0.1;
            if (angle > 256) angle = 0;
            rotate_sprite(screen, tank, x, y, itofix(angle));
        }

        //display angle
        textprintf_ex(screen, font, 0, 10, WHITE, 0,
            "Angle = %f", angle);
    }
}
allegro_exit();
return 0;
}
END_OF_MAIN()

the program triggering the breakpoint is: crt0msg.c off of the disk.
snippet of code:

         #ifdef _DEBUG
        /*
         * Report error.
         *
         * If _CRT_ERROR has _CRTDBG_REPORT_WNDW on, and user chooses
         * "Retry", call the debugger.
         *
         * Otherwise, continue execution.
         *
         */

         if (rterrnum!=_RT_CRNL&&rterrnum!=_RT_BANNER&&rterrnum!=_RT_CRT_NOTINIT)
        {
            if (1 == _CrtDbgReport(_CRT_ERROR, NULL, 0, NULL,rterrs[tblindx].rterrtxt))
                _CrtDbgBreak();
        }
        #endif  /* _DEBUG */

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似梦非梦 2024-12-19 21:32:09

tank = load_bitmap("C:\Users\Jason\Desktop\module7\tank.bmp", NULL);

您的编译器应该警告您有关该字符串的信息,因为它包含无效的转义字符。您应该使用双反斜杠或单正斜杠:

tank = load_bitmap("C:\\Users\\Jason\\Desktop\\module7\\tank.bmp", NULL);
// or
tank = load_bitmap("C:/Users/Jason/Desktop/module7/tank.bmp", NULL);

建议使用后一种格式,因为它是跨平台的。 (减去关于硬编码绝对路径的全部内容。)

最后,您确实需要检查返回代码:

if (!tank) {
  // gracefully report error and exit      
}

否则程序将在其他地方崩溃并且更难以调试。

tank = load_bitmap("C:\Users\Jason\Desktop\module7\tank.bmp", NULL);

Your compiler should be warning you about that string since it contains invalid escaped characters. You should use double back slashes or single forward slashes:

tank = load_bitmap("C:\\Users\\Jason\\Desktop\\module7\\tank.bmp", NULL);
// or
tank = load_bitmap("C:/Users/Jason/Desktop/module7/tank.bmp", NULL);

The latter format is recommended because it is cross platform. (Minus the whole bit about hard coding an absolute path.)

Finally, you really need to check return codes:

if (!tank) {
  // gracefully report error and exit      
}

Otherwise the program will crash somewhere else and it will be harder to debug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文