coding Q - allegro - FAIL struct with array of BITMAP
category: general [glöplog]
I'm working on some code for a game, here is a snippet.
It builds fine. I did some bread crumb debugging and found that the line it crashes on is...
anim.frame[i] = load_tga(fullstring.c_str(),false);
I did some searching and found someone working with arrays of bitmaps, and they mentioned to set each frame to 0 before starting. I tried this with something like this...
for(int i = 0; i < anim.frames; i++){
anim.frame[i] = 0;
}
Still no luck. :(
Any help would be most appreciated! =]
Code:
struct animImage{
string animName; //name of animation
int frames; //num of frames
BITMAP * frame[999]; //array to hold frames
int loaded;
int origXres; //original res of frame (will be scaled)
int origYres; //" "
};
int main(){
animImage win1;
win1.animName = ("win1");
win1.frames = 6;
win1.loaded = 0;
win1.origXres = 800;
win1.origYres = 600;
win1 = load_anim(win1);
}
//loop adds each frame of animation to an array of bitmaps
animImage load_anim(animImage anim){
string path = ("data\\anim\\");
string ext = (".tga");
string fullstring = "";
for(int i = 0; i < anim.frames; i++){
//int to string code
string s;
stringstream out;
out << i;
s = out.str();
fullstring = path + anim.animName + s + ext;
anim.frame[i] = load_tga(fullstring.c_str(),false);
}
anim.loaded = 1;
return anim;
}
It builds fine. I did some bread crumb debugging and found that the line it crashes on is...
anim.frame[i] = load_tga(fullstring.c_str(),false);
I did some searching and found someone working with arrays of bitmaps, and they mentioned to set each frame to 0 before starting. I tried this with something like this...
for(int i = 0; i < anim.frames; i++){
anim.frame[i] = 0;
}
Still no luck. :(
Any help would be most appreciated! =]
According to the documentation:
BITMAP *load_tga(const char *filename, RGB *pal);
why is your RGB pointer set to false?
BITMAP *load_tga(const char *filename, RGB *pal);
why is your RGB pointer set to false?
That is funny, I never just tore through the Allegro manual and found nothing that says its ok to give "false" as an arg to load_tga. Its funny because for some reason it works. LOL
As for the problem, I solved it. My code is all in 1 file and its near 2000 lines. I haven't had my morning cup of coffee so I wasn't paying good attention, and put the load_anim() before my sysInit(). The code was crashing because I hadn't initialized Allegro before calling load_tga() inside of my function. DOH!
One question leads to another, now I must know why passing false works...
As for the problem, I solved it. My code is all in 1 file and its near 2000 lines. I haven't had my morning cup of coffee so I wasn't paying good attention, and put the load_anim() before my sysInit(). The code was crashing because I hadn't initialized Allegro before calling load_tga() inside of my function. DOH!
One question leads to another, now I must know why passing false works...
I assume it works because false == NULL and it seems that allegro just ignores the second parameter if it's a NULL pointer.
Missed this part in the manual.
Code:
The pal argument may be NULL. In this case, the palette data are simply not returned. Additionally, if the file is a truecolor image and the destination color depth is 8-bit, the color conversion process will use the current palette instead of generating an optimized one.
so "b0ib0t", what did we learn today?
ahyes, rtfm!
ahyes, rtfm!
I did read it, but I had missed over part. What I learned today was rtfm2x ;)
and coffee :)
Weird!! I did find the answer after having a cup of coffee. I think the lesson to be learned here is, do not code before having coffee!
Shouldn't
string path = ("data\anim\");
be
string path = ("data\\anim\\");
Just an idea...
string path = ("data\anim\");
be
string path = ("data\\anim\\");
Just an idea...