Mail Archives: djgpp/1997/12/23/13:15:37
Mark Phillips <bigphil AT solutions DOT mb DOT ca> schrieb im Beitrag
<349d836a DOT 0 AT news3 DOT escape DOT ca>...
> I have a program which uses allegro to load 6 bitmaps, all of size
> 77x105 and i want to keep writing them over top of each other to do
> some crude animation. However, half of the time when I try to compile
> the program, the compiler gives me the error: "virtual memory
> exhausted" the other half of the time it compiles but i get a general
> protection fault after it has displayed 2 frames. What am I doing
> wrong? here is the source if you're interested (I am just trying stuff
> out and so I just modified one of the allegro examples). oh yeah by
> the way, i accidentally overwrote allegro example #15 so if someone
> could just post ex15.c that would be great too.
>
Here is a modified version of your example, this works on my machine.
Watch the comments for explanation
====Begin====
#include <stdlib.h>
#include <stdio.h>
#include <allegro.h>
/* ^ ^
if allegro.h is in your Include directory */
#define MAX_IMAGES 4
/* ^^^^^^^^^^
it makes programming easier to define your constants */
int main()
/* ^^^
use int, because main must return int */
{
int i;
BITMAP *the_image[MAX_IMAGES];
PALLETE the_pallete[MAX_IMAGES];
char file_name[MAX_IMAGES][13] = {"run1.bmp",
"run2.bmp",
"run3.bmp",
"run4.bmp"};
/* this gives you a more flexibility
*/
allegro_init();
/* you must call allegro_init() before any of the allegro functions!
maybe this was the cause of the protection fault */
install_keyboard();
install_timer();
/* this is needed for rest() */
/* read in the bitmap files */
for (i=0; i<MAX_IMAGES; ++i) {
the_image[i] = load_bitmap(file_name[i], the_pallete[i]);
if (the_image[i] == NULL) {
allegro_exit();
fprintf(stderr, "Error reading bitmap file \"%s\"\n", file_name[i]);
/* stderr is better for debuging, RHIDE shows this message in a
special window */
exit(1);
}
}
if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0)!=0)
exit(1);
i = 0;
while(!key[KEY_ESC]) {
/* select the bitmap pallete */
set_pallete(the_pallete[i]);
/* blit the image onto the screen */
blit(the_image[i], screen, 0, 0, 0, 0, 77, 105);
rest(100);
/* ^^^^^^^^^^ it waits for 100 milisecs */
++i;
if (i==MAX_IMAGES)
i=0;
}
for (i=0; i<MAX_IMAGES; i++)
/* destroy the bitmap */
destroy_bitmap(the_image[i]);
readkey();
allegro_exit();
/* exit allegro before you exit your programm */
exit(0);
}
=====End=====
Hope this helps
Ingo
--
Ingo Ruhnke
grumbel AT gmx DOT de
http://home.pages.de/~grumbel
- Raw text -