Hello! I have a problem with memory (I think) so I tried to destroy the bitmaps with various commands, but I couldn't.
I received a lot of help from here:
Please read that (the 5th page is the most important, but read the others if you want).
But now it's more Allegro-based problems, so I decided to post here.
My code:
The ideia is to make a kind of a slideshow... But when I get to this part:
(...) bmp = load_bitmap("6.bmp", palette); draw_sprite(screen, bmp, 0, 255); sleepTime=35; sleep(sleepTime); clear_bitmap(bmp); bmp = load_bitmap("Ubuntu.bmp",palette); draw_sprite(screen, bmp, 1, 1); (...)
It crashes and exits. It displays the 6.bmp and does the sleeptime properly... But then it exits. I think it is the memory that is full, so it exits. It doesn't clear the bitmaps! I already tried with various and different commands, but it just don't works! The bitmaps aren't deleted!
Can you help me, please? When I thought I finished...
Thank you.
Regards,
JPCanaverde
The code tag syntax is <code></code>. Please edit your post so the code becomes readable...
May I ask... Where's the edit button?
EDIT:
Never mind, found it.
void destroy_bitmap(bmp);
That isn't how you call a function in C or C++. The compiler is going to be mighty confused with that. remove the void keyword, and it aught to work.
As I told, I tried with different commands. I tried that too, and happens the same.
He meant change all the "void destroy_bitmap(bmp);" to "destroy_bitmap(bmp);"
Try checking load_bitmap for failure, if it returns NULL, it couldn't load the image, and draw_sprite will crash.
Removed the void (again) and still does the same.
How do I check the load_bitmap? I googled, but only found how to check the graphics, sounds, and such.
bmp = load_bitmap("6.bmp", palette); if(!bmp) { set_gfx_mode(GFX_TEXT,0,0,0,0); allegro_message("Can't load 6.bmp"); return 1; }
I did that, but does the same. I checked 6.bmp and Ubuntu.bmp. It just doesn't work, but doesn't give me any message. But I think I know why.
I think the image is too big. I'll try to reduce the size and quality. I give feedback later.
EDIT:
I added the following lines next to int sleepTime:
acquire_screen(); textout(screen, font, "Linguagem Binária\n", 255, 0, 255);
And it just opens a black window and closes. What can I do?
Before, I also tried to replace the destroy_bitmap(bmp); with destroy_bitmap("name.bmp").
Example:
destroy_bitmap("1.bmp");
It destroys the bitmap, but closes the next moment.
What can I do? I'm desesperated!
Please post the current state of your program. It seems like you made many adjustments to your code, so it's very hard to tell what's going wrong and why.
What can I do? I don't get it... It just ignores the code in front of the 6.bmp and its sleeptime. It's like the rest doesn't exist.
Another thing... When I compile an Exe in my Ubuntu box, it doesn't run on Windows. Why? Do I need something more installed? It just opens a DOS Windows and closes it the next moment.
I don't wanna rush you (because you have your life, of course) but I need to finish this to Tomorrow night. It's for school...
Thank you.
Bye.
Ok, first of all:
Whenever you duplicate lines of code, what you really want is a function. Like this one:
You're also calling destroy_bitmap on a string in your example code, which is a bad idea.
You cannot run your ubunto executable in windows, because it's not made for windows, but for ubunto. While you can cross compile, I don't think that's what your're doing.
I don't get it. I removed this:
acquire_screen(); textout(screen, font, "Linguagem Binária\n", 255, 0, 255);
And added what you said, so I got this code:
But it stops at the time of displaying 5.bmp. What am I doing wrong?
------------------------------------------------------------------------------------
And yes, I'm cross-compiling. I make all my tests in .sh, but I tried to compile an .exe to see if it worked on Windows, and it doesn't.
I mean... It's only needed to place in the makefile to make a .exe, right? Or do I need something more?
What class do you need this for? What's the assignment? I somehow doubt that your teacher requested you to write a slideshow program at the level that you demonstrate. If you can write a simpler program for the grade then I suggest you do so...
You seem to be a pretty big n00b for such a complicated program (by school standards). You don't even seem to comprehend subroutines and you're trying to use a third party library that you don't understand and are trying to cross-compile from Linux to Windows.
It might be best to accept a failed grade and find yourself a C tutorial and start from scratch.
The help you've been receiving seems to go right over your head.
There are many things wrong with your code. For starters, you must always check return values to ensure a called subroutine succeeded. If it didn't, continuing on might crash your program (which, surprise, is happening).
Here's a clue. Try deleting all the mess you wrote in main. Add the allegro init routines, and use only the function that spellcaster gladly wrote for you.
EDIT:
by school standards
You know, I've always wondered, what are these 'school standards' in early programming classes. The only school that I knew of that had programming in its last years was public and badly managed, so I never went there.
So I never knew how much do they learn there. A slideshow program looks pretty basic to me, considering you don't even need to treat something like a logic loop, just a sequence of commands.
It's the first class of the morning of Wednesday.
The teacher didn't asked me to do... It is for Technological Education, and I proposed to, since we talked a bit about Binary Language. It's the final work for the year (I'm at the 7th, 12 years) and we were proposed to do what we wanted, practical or theoretical (mine counts as practical), but that had to do with the matter which had given.
As I had a little experience with C on PSP, i thought it would be fun to do it for PC.
If I need to, I compile Windows-Windows... And if it really has to be, I think I can do a extense "Hello World".
But, I really want to try. If I see I really can't, I give up and do the Hello World. But I wanna try. I love this stuff. In my holidays, I'll dedicate to C. But now I'm in a hurry...
Thank's for all help so far.
If you're 12, that program is really not that bad. So, heads up for that 
Ok, I'm passing something. I did what you told me, got this code:
And I get errors compiling!
I checked the code, and I think everything is "introduced". I don't get it...
You missed the #includes.
Oh right. I have also no idea if that code compiles, since I "coded" it typing into the reply field.
If you find any bugs, you can keep them. They are yours!
, how could I miss that? 
Anyway, I discovered the problem. And the problem is... Ubuntu.bmp. It finally showed up a message saying that it couldn't be loaded! I don't know why. Maybe the image is too big...
Gotta check all that tomorrow. But finally I know the problem...
Thank's for all, see you tomorrow.
Double check the filename (lower/upper case, spaces). Normally it's these small things that cost you a lot of time.
That's one of the reasons why using functions is a good thing: add a check once, get the message whenever it's used 
Try using this slightly changed version of the function. You'll also have to
#include <stdio.h>
Since the loading code is now in a function, it's very easy to add an extra check (to see if the filename is the issue, or if it's a problem with the data itself).
I also removed the PALETTE, since it's not used anyway.
Oh, and I just wanted to repeat that you'll need to include stdio.h for this to work.
, it was the name after all. Instead of "ubuntu.bmp" in the code, I had "Ubuntu.bmp". XD
So, now my code works. Thank you very much guys. I just have a bit of a problem, but nothing that can't be resolved with a little of patience: the slideshow is too slooooow (it doesn't respect the sleeptimes, it just goes and goes, too slow). I can say to the teacher to wait a little bit, I guess. ^^
My final, working, code (double-checked this time):
Again... Thank you. See you next time! 
P.S. What to you suggest for practicing?
Bye bye.
Of course your program is too slow, because you're waiting twice as long.
The function I wrote takes care of loading, displaying, waiting and destroying the bitmap.
Here's your code w/o the stuff that's not needed
The last number in each call is the sleep time. Which is in seconds. And 10 seconds are a long time. Even 3 seconds are pretty long when all you do is look at a screen.
See my (new) comment in the load_and_display function
btw, sleep is a non-standard function, so may not be supported by all C compilers. You also don't need to worry about the palette when using anything but 8 bit graphics.
No, the 1,2,3,4(etc) images are text. I cronometered myself reading each one, and puted the sleeptime accordinlgy. It was taking longer than the sleeptimes.
So, the final code is supposed to be this, right?:
It isn't the same slow, but it is slow (when I say slow, I mean it is passing the sleeptimes). Am I missing something?
So, the final code is supposed to be this, right?:
The last parameter of the function Spellcaster wrote for you is the delay. Instead of passing 20 to it, and then sleeping again (say for 40s)between calls, just add the second sleep time to the first (and pass 60 to the function).
You also don't need to keep destroying the bmp bitmap in the main loop, as you never even use it (you can actually remove it's declaration).
It isn't the same slow, but it is slow (when I say slow, I mean it is passing the sleeptimes). Am I missing something?
Sleep probably isn't very reliable. You could try using Allegro timers instead.
No, the final code is supposed to be what I posted above.
Why the heck did you think I took the time to put that code together and tell you that I removed all the stuff that's not needed if you decide to put it back in again?
Hm?
And if you really want seconds, replace the call to sleep( delay )
with rest( delay * 1000 ) - should in theory do the same thing, but work better.
If you change it to use rest() you'll also need to call install_timer() after you init allegro.
BTW you can click any allegro and standard-c function in the code blocks here to see the man page for them, which might give you further info.
Now I got it: Delay is the sleep! I didn't copy-paste your code because I thought I had to put the SleepTimes too. And it was taking too long because I was wating 2 times.
OK, thank's. Now it works! Woo hoo!
EDIT:
It just works on my computer, with Ubuntu. I tried with Windows in a second computer and with Ubuntu on a third computer, but they don't work! I don't get it! What's happening? I really don't want to take my laptop to school...