Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » OS X 10.5 problem

Credits go to Edgar Reynaldo, Peter Hull, and Ron Novy for helping out!
This thread is locked; no one can reply to it. rss feed Print
OS X 10.5 problem
dac118
Member #9,617
March 2008

I just installed the newest version of Allegro, but when I try to use bitmaps all I can use are examples, not my own. I fI use my own, I get a white square instead of a window, then it crashes.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

When you say newest version do you mean the newest stable version , the newest release of the WIP version , or SVN version, so on...?

Post the version number of Allegro you downloaded. As for the code not working post what you're using that isn't working.

dac118
Member #9,617
March 2008

I'm using Allegro v4.2.2 The code that doesn't work is as follows:

#include <Allegro/allegro.h>

int main(int argc, const char *argv[])
{
allegro_init();
install_keyboard();
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
BITMAP *map = NULL;
map = load_bitmap("picture.bmp", NULL);
BITMAP *buffer = NULL;
buffer = create_bitmap(610,400);
draw_sprite(buffer, map, 0, 0);
blit(buffer, screen, 0,0,0,0,610,400);
readkey();
clear_bitmap(buffer);
destroy_bitmap(map);
destroy_bitmap(buffer);


return 0;
}
END_OF_MAIN();

610 x 400 is the image size of picture.bmp

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You can use code tags in the forum to display your code in a formatted window. It makes it easier to read. You can also edit your post.

<code>
Code goes here
</code>

If the code you posted is crashing, it's likely because you used a relative path name to load your "picture.bmp" file. The load_bitmap and create_bitmap functions will return NULL if they fail to load/create their bitmaps respectively and you should check for it.

The directory that will be searched for the file is likely the directory the program was run from and if it is not there load_bitmap will fail. Try using the absolute path of the file and see if that will work. However , this will reduce portability if you use an absolute path. It's best to build up an absolute path to the file during runtime so the absolute path will be correct on every machine it's run on.

BITMAP* pic = load_bitmap("picture.bmp" , NULL);
if (!pic) {return 0;}// loading failed , quit / deallocate memory

dac118
Member #9,617
March 2008

I tried the direct path, but it still failed. I tried using Terminal to compile it, and when I ran it using ./a.out, after it crashes, it said:

Warning once: This application, or a library it uses, is using NSQuickDrawView, which has been deprecated. Apps should cease use of QuickDraw and move to Quartz.
a.out(5928,0xf0081000) malloc: *** mmap(size=4294238208) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Bus error

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Don't use a semi-colon after END_OF_MAIN() , it's incorrect.

Try compiling this and running it. If the graphics mode is set correctly the screen will appear red at the beginning of the program. Press a key and if the screen turns yellow the buffer was allocated correctly. Press another key and if the picture bitmap was loaded okay the screen will turn green. Press another key to attempt to display your picture. Be sure to replace picture.bmp with the absolute path of the file on your computer. Perhaps filename directory slashes are not being written correctly?

1#include <Allegro/allegro.h>
2 
3 
4int main(int argc, const char *argv[]) {
5 allegro_init();
6 install_keyboard();
7 install_timer();
8 
9 set_color_depth(16);
10 set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
11 clear_to_color(screen , makecol(255,0,0));
12 clear_keybuf();
13 readkey();
14 rest(200);
15 
16 BITMAP *buffer = NULL;
17 buffer = create_bitmap(610,400);
18 if (buffer) {clear_to_color(screen , makecol(255,255,0));}
19 clear_keybuf();
20 readkey();
21 rest(200);
22 
23 BITMAP *map = NULL;
24 map = load_bitmap("picture.bmp", NULL);
25 if (map) {clear_to_color(screen , makecol(0,255,0));}
26 clear_keybuf();
27 readkey();
28 rest(200);
29 
30 draw_sprite(buffer, map, 0, 0);
31 blit(buffer, screen, 0,0,0,0,610,400);
32 clear_keybuf();
33 readkey();
34 
35 clear_bitmap(buffer);// unnecessary since you're just about to destroy it anyway
36 destroy_bitmap(map);
37 destroy_bitmap(buffer);
38 
39 return 0;
40}
41END_OF_MAIN()

dac118
Member #9,617
March 2008

Got to yellow, then when I pressed a key, it crashed, without turning green. As for the slashes, I used "/". Could the problem have anything to do with the depth?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Since the screen didn't turn green , then load_bitmap was returning NULL which means it failed.

If you set a color depth and call set_gfx_mode then until you do it again any bitmaps you load with load_bitmap will be converted to the current color depth. I think the problem is just with the file path. Try something like this :

char filepath_pic[] = "absolute/path.bmp";
fix_filename_slashes(filepath_pic);
BITMAP* map = load_bitmap(filepath_pic , NULL);

I'm not sure what MacOS X likes for slashes so maybe that will fix it.

dac118
Member #9,617
March 2008

It flashes red, then stays white, and then when I press a key, yellow. It doesn't crash, but stays yellow.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Well , that's really bizarre with the screen going white and all. Especially since there's no code in there to do that.

Since I don't see any MacOS X builds on the allegro files page I assume you compiled Allegro yourself. Did you follow everything in the allegro\docs\build\macosx.txt file?

What options did you pass to the compiler when you compiled your program and linked it?

dac118
Member #9,617
March 2008

I compiled the projects in Xcode, so I didn't have to pass any options. When I did compile the file in Terminal, I just typed "g++ -framework Allegro" and then the location. I did compile Allegro myself at first, but then I found an automatic installer and used that (it was v4.2.2). Neither installations worked on my own image. I don't known if this could be of the same cause, but when I just tried to use g++ to compile a C++ file, I got an error saying "expected unqualified-id before ‘using’" Maybe my gcc's broken.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

According to allegro/docs/build/macosx.txt in the "Using allegro from the command line" section it says to

Quote:

You can also link against the Allegro framework, providing you previously
installed it via make install-framework:

gcc myfile.c -o myprogram `allegro-config --frameworks`

Using backticks around "allegro-config -- frameworks".

You can also find a list of linking options by using

Quote:

Run allegro-config without any arguments for a full list of options.

Take another look over macosx.txt and see if there's something you missed.

dac118
Member #9,617
March 2008

I Reinstalled it, tried command line commands, and Xcode compilation, but it still crashes. When I switched to using a .cpp for the main, it still didn't work, but the debugger reported: "EXC_BAD_ACCESS:"
AL_INLINE(void, draw_sprite, (BITMAP *bmp, BITMAP *sprite, int x, int y)
It was in an Allegro data file, "draw.inl" Does this mean my installation is messed up? The file I was trying to compile was the Lesson 5 source of the Loomsoft tutorial.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Are you using the right allegro-config options?

Since I'm not a MacOS X user myself , I'm not entirely sure what's going on.
Post the exact command line options you used to compile and link your program when it failed. If those are correct then maybe we can narrow it down to a bad installation. Did you keep a text log transcipt of the entire Allegro library compilation and linking process? That would help determine whether Allegro was installed successfully for your setup.

dac118
Member #9,617
March 2008

I just used the 'gcc myfile.c -o myprogram `allegro-config --frameworks`' with my file's name. As for the installer log, I'm not sure where it's at. It can't be a location problem, though, because I put an image in the same folder as the lesson 4 image. The lesson 4 image works, but the second I use my own, it doesn't. I adjusted the sizes, but still, it crashes. Oddly enough, When I try "g++ lesson4.cpp -o myprogram `allegro-config --frameworks`" (using lesson 4 image), it crashes.

Peter Hull
Member #1,136
March 2001

To me this looks more like something is unusual about your bitmap, given that the lesson 4 bitmap doesn't crash and your bitmap does. Can you attach that bitmap for us to have a look at?

Pete

dac118
Member #9,617
March 2008

It's not very detailed, but…

Peter Hull
Member #1,136
March 2001

I think you might have found a bug in Allegro, but on the other hand I can't believe this has never been seen before. I did some tracing with gdb and it fails here
#4 0x0001a55f in create_bitmap_ex (color_depth=24, width=55, height=-53) at src/graphics.c:1052 1052 ASSERT(height > 0);
According to the docs, the height of a bitmap is allowed to be negative; it indicates a top-down bitmap rather than a bottom-up one. However Allegro doesn't handle that case.

What tool did you use to create your bitmap?

Pete

dac118
Member #9,617
March 2008

AppleWorks for OSX, but I saved it using Preview.

Peter Hull
Member #1,136
March 2001

Just to check I'm right, can you try with this bitmap? (works for me) What I did was used convert from ImageMagick to 'fix' it
convert shape.bmp picture.bmp

This bug doesn't seem to be OS X specific.

Pete

dac118
Member #9,617
March 2008

It worked with the bitmap. Does this mean I just have to download ImageMagick and fix my bitmaps before adding them to the file?

Ron Novy
Member #6,982
March 2006
avatar

That image you linked doesn't show up in Explorer, but it does show a white box in FireFox.

I just think it's funny how Apple always finds those little known and rarely implemented features created by Microsoft and then implements them to make Microsoft look stupid.

----
Oh... Bieber! I thought everyone was chanting Beaver... Now it doesn't make any sense at all. :-/

Peter Hull
Member #1,136
March 2001

Ron: I'll bet Bill G has his head in his hands right now!!

dac118: Depends if you're going to make all your bitmaps in AppleWorks and save them with preview. Anyway there will be a patch to Allegro coming along soon, which will fix this. You can check, but ImageMagick might already be installed (I can't remember if it was or if I installed it myself)

Pete

dac118
Member #9,617
March 2008

Thanks for all the help, now everything works! Although I do have one more question: how would I handle text input (i.e strings) using cin >> or something else?

Go to: