Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allocation, resize and exiting issues [A5]

This thread is locked; no one can reply to it. rss feed Print
Allocation, resize and exiting issues [A5]
m4rcdbk
Member #14,386
June 2012

Hello all.

I've done a bit of research through the site and have found very little conclusive, so I figured I'd make a post to address a few issues I'm having with some code.

The first thing I'll note, is that I've stepped away from Allegro for a fair amount of time (about 2 years or so), so when I saw that Allegro 5 had dropped I went for the download. Right now, I'm using GCC version 4.4.1, and Allegro 5.0.0 RC3. My IDE is code::blocks.

My First 3 issues:

When running the executable, I had to run in compatibility mode with windows XP SP2 in order for it to successfully allocate memory without heap fragmentation. Is this an issue with just the version of allegro I'm using, or one with windows 7? (Code provided below other questions).

Secondly, I get another similar issue when trying to open a file. The file has been verified to exist at the path given, and the access rights to the file are everyone. Which, just as an added precaution I allowed it to run as administrator.

Lastly, when I exit the code with the al_uninstall_system(); it crashes with (yet again) another sigserv.

I attribute these issues to either myself with a bad programming practice somewhere along the way, or with me using an early version of Allegro 5.

The code:

#SelectExpand
1int main() 2{ 3 al_init(); 4 al_init_image_addon(); 5 6 bmp = al_create_bitmap(100, 100); //Crashes here with SIGSERV, when run in compatibility mode this succeeds 7 8 if(bmp) 9 { 10 bmp = al_load_bitmap("B:\\d.bmp"); // it crashes here with a sigserv. debugger points to the DLL itself, unless run in compatibility mode 11 if(bmp) 12 { 13 //All is well 14 float width = al_get_bitmap_width(bmp); 15 float height = al_get_bitmap_height(bmp); 16 al_draw_scaled_bitmap(bmp, 0, 0, width, height, 0, 0, 100, 100, 0); //Crashes here, with or without the compatibility mode. SIGSERV, debugger points to this function call 17 al_save_bitmap("B:\\temp.bmp", bt); 18 } 19 } 20 21 al_shutdown_image_addon(); 22 23 al_uninstall_system(); //Crashes here, no matter what kind of compatibility settings I have. 24 return 0; 25}

Lastly, When I tried to update to the latest Allegro (5.0.6) it'd get a Missing DLL error, which through research on here says to link with -static-gcc, and 2 other things. Since I've since removed the linking's and reverted to 5.0.0 again I don't have them to copy and paste back. But I did attempt them.
I've tried other versions with varying results, none good.

Any and all information, questions, comments or thoughts to help me out would be greatly appreciated.

jmasterx
Member #11,410
October 2009

What about creating a display, it is pretty important to Allegro that you have one.

Matthew Leverton
Supreme Loser
January 1999
avatar

Your code isn't doing what you think it is. I don't even know what bt is.

You need to call this al_set_target_bitmap(bmp); after creating your first bitmap. Then you need to give your second bitmap a different variable.

al_draw_scaled_bitmap() will need to be called with your second bitmap. Then call al_save_bitmap(bmp) (with your first bitmap).

Nothing should be crashing if you do that. If it still crashes (particularly with the latest 5.0.x release), then I suspect you're linking against Allegro libraries that are incompatible with your compiler or something.

m4rcdbk
Member #14,386
June 2012

Thanks for the replies, and hopefully I can clear up some confusion.

The code provided was a scaled down snippet of the main project in and of itself.
However, the code snippet should have had "bmp" and "bt" as two bitmaps, I might have modified them when pasting them over, which is still my fault.

I do understand the reasoning for a display, but I figured since what I was using allegro for which is gathering pixel data, and resizing an image. Displaying a picture would be partially irrelevant, granted I didn't take into consideration as far as what's working behind the scenes.

I have modified my code to include the al_set_target_bitmap(bmp), as follows

#SelectExpand
1int main() 2{ 3 al_init(); 4 al_init_image_addon(); 5 6 ALLEGRO_BITMAP *bmp = al_create_bitmap(100, 100); //Crashes here with SIGSERV, when run in compatibility mode this succeeds 7 ALLEGRO_BITMAP *bt; = al_create_bitmap(100, 100); 8 if(bmp) 9 { 10 bmp = al_load_bitmap("B:\\d.bmp"); // it crashes here with a sigserv. debugger points to the DLL itself, unless run in compatibility mode 11 if(bmp) 12 { 13 //All is well 14 al_set_target_bitmap(bt); 15 al_draw_bitmap(bmp, 0, 0, 0); 16 float width = al_get_bitmap_width(bmp); 17 float height = al_get_bitmap_height(bmp); 18 al_draw_scaled_bitmap(bt, 0, 0, width, height, 0, 0, 100, 100, 0); 19 al_save_bitmap("B:\\temp.bmp", bt); 20 } 21 } 22 23 al_shutdown_image_addon(); 24 al_uninstall_system(); //Crashes here, no matter what kind of compatibility settings I have. 25 return 0; 26}

As for linking, as I said I've got GCC version 4.4.1, which I've downloaded the latest allegro binaries for. I get that stdc++6.dll error, even with different link options, so I've gone back a few releases. Which, again, if I knew how to resolve that I'd have 0 issues there with keeping most recent.

I have not included the adding an allegro display yet, as I just wanted to give a quick update on the code to address Matthew's points, when I get back on later today I will include and update.

As always, your time is very much appreciated as is every bit of help.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Allegro 5.0.0rc3 is WAY OLD, update to the latest version - 5.0.6. Or use SVN 5.1.X if you like cutting edge stuff...

Your latest code has a memory leak - don't store a loaded bitmap* in the same pointer you stored one you created without destroying the one you created first.

Ex.

al_init();
al_init_image_addon();
//ALLEGRO_DISPLAY* disp = al_create_display(640,480);// optional, but if you don't do this, any bitmaps created HAVE to be memory bitmaps

ALLEGRO_BITMAP* disk_image = al_load_bitmap("myfile.png");
ALLEGRO_BITMAP* target = al_create_bitmap(100,100);

al_set_target_bitmap(target);
al_draw_scaled_bitmap(disk_image , 0 , 0 , al_get_bitmap_width(disk_image) , al_get_bitmap_height(disk_image),
                                   0 , 0 , 100 , 100 , 0);
al_save_bitmap("myfile_100x100.png" , target);

m4rcdbk
Member #14,386
June 2012

Allegro 5.0.0rc3 is WAY OLD, update to the latest version - 5.0.6. Or use SVN 5.1.X if you like cutting edge stuff...

I can't get it to execute on "run", or double click. Keeps mentioning stdc++6.dll (or whatever it is), yet I've tried other members linking methods to resolve it. That's the only reason I'm not using 5.0.6.

As for the memory leak, I see what you're saying.

bamccaig
Member #7,536
July 2006
avatar

The latest code that you posted has a syntax error in it. Nonsensical indentation is generally a good indication that the author doesn't have the mental capacity for programming. :-X I certainly can't be bothered to help them until they fix it.

al_load_bitmap allocates the bitmap data structure so there's no need to create one first. Even if you did have to, if you aren't passing it in then there's no way for it to be used by the function. Obviously, you are quite new to C. I would suggest learning the language better before trying to use a third party library. And encourage you to be less lazy (I infer laziness from your code).

Matthew Leverton
Supreme Loser
January 1999
avatar

bamccaig said:

Even if you did have to, if you aren't passing it in then there's no way for it to be used by the function.

Oh yeah?

#SelectExpand
1static ALLEGRO_BITMAP *last_bitmap = NULL; 2 3ALLEGRO_BITMAP *al_create_bitmap(int w, int h) 4{ 5 last_bitmap = make_bitmap(); 6 return last_bitmap; 7} 8 9ALLEGRO_BITMAP *al_load_bitmap(const char *filename) 10{ 11 if (!last_bitmap) blow_up(); 12 13 load_bitmap_into_global(last_bitmap); 14 return last_bitmap; 15}

8-)

Thomas Fjellstrom
Member #476
June 2000
avatar

m4rcdbk said:

I can't get it to execute on "run", or double click. Keeps mentioning stdc++6.dll

Its the C++ standard library. You probably want to either copy that into your folder, or link it statically. --static-stdlibc++ or something.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Trent Gamblin
Member #261
April 2000
avatar

or link it statically. -static-libstdc++ or something.

FTFY. And if you get errors about some missing libgcc....dll, -static-libgcc.

Thomas Fjellstrom
Member #476
June 2000
avatar

what he said.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

m4rcdbk
Member #14,386
June 2012

Alright. Got it guys.

Much appreciated.

The heap corruption was from the pointers, and then the linking resolved the uninstall_system issue as well. All's well.

Thanks!

Go to: