2

I have a 114x114 bitmap called "x.bmp" in my debug folder and this simple code

#include <allegro.h>

BITMAP *Sprite;

int main(){
    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

    Sprite = load_bitmap( "x.bmp", NULL);

    acquire_screen();
    draw_sprite(screen, Sprite, 50, 50);
    release_screen();

    readkey();

    return 0;

}   
END_OF_MAIN();

But it freezes up and looks like this Frozen screen

But when I just run the AllegroTest.exe file via windows explorer it works...

I am using Allegro 4.2.3 and MSVC++ 2008

Edit: here's something interesting I get in my debug output window:

al-gfx INFO: The driver will wait for vsync.
al-gfx INFO: set_gfx_card success for 640x480x16.
Assert failed at line 250 of c:\users\matthew\desktop\allegro\4.2\include\allegro\inline\draw.inlThe thread 'Win32 Thread' (0x137c) has exited with code -805306369 (0xcfffffff).
The thread 'Win32 Thread' (0x25b8) has exited with code -805306369 (0xcfffffff).

c:\users\matthew doesn't exist!!! I have no user named matthew?

Mark Lalor
  • 7,820
  • 18
  • 67
  • 106
  • If the demo works it's your code ... do you have the hardware acceleration flag set, also check if your bitmap actually loaded before attempting to draw it for starters then probably avoiding leaking the memory by calling `destroy_bitmap` after :P – AJG85 Apr 22 '11 at 22:42
  • What is the hardware acceleration flag and how do I set it? – Mark Lalor Apr 22 '11 at 23:46
  • Also how do you check that the bitmap loaded? – Mark Lalor Apr 22 '11 at 23:51
  • `load_bitmap` will return 0 if it fails so you can do `if (!Sprite)` to check if it failed to load in your example. Use configurable directories and relative paths. – AJG85 Apr 25 '11 at 15:37

1 Answers1

4

The bitmap most likely can't be loaded.

When you start an application from the Visual Studio debugger, the default working directory is the project directory. When you start an application via explorer, the working directory is the directory the executable is in. Normally, the project directory will be ...\SolutionName\ProjectName\.

When you provide a relative path, i.e. x.bmp, the application will search the working directory for it, followed by some other directories, such as those listed in the PATH environment variable. It's usually preferable to give an absolute path, if possible.

Most likely your image file is in the same directory as the executable, but this directory isn't the project directory.

Collin Dauphinee
  • 13,664
  • 1
  • 40
  • 71
  • +1 You are right! When I use an absolute path it works. But where should I put my `x.bmp`... I don't want to use absolute paths in my programs, they would not be portable. – Mark Lalor Apr 23 '11 at 00:38
  • Put a copy of the file in your project directory. – Collin Dauphinee Apr 23 '11 at 01:04
  • When loading an external resource with Allegro 4, a relative path will only be resolved from the current working directory. The PATH env is irrelevant. Also, I believe MSVC always starts up in the directory that the EXE is in. However, this directory will be something like /Debug or /Release. You probably have your data files in a sibling folder. To get around this, you can instruct MSVC to place the EXE into some folder like "bin" which would contain a "data" subfolder. Then your relative paths will work as expected both within and outside the IDE. – Matthew Apr 24 '11 at 00:03