|
RLE sprites are rats! |
The Master
Member #4,498
April 2004
|
I don't think RLE sprites like me very much, or at least the ones that have been created from a sub-bitmap of a frame-strip. Source code: We can only do what we feel is right each moment as we live it. |
Peter Wang
Member #23
April 2000
|
FYI you don't need to put END_OF_FUNCTION() after every single function, only the ones that you intend to call LOCK_FUNCTION() with. Secondly, xor is a C++ keyword so you can't use it as the name of a member variable. Finally, the bug is possibly due to this: std::vector<RLE_SPRITE> anim_data; You'd want a vector of pointers to RLE_SPRITEs instead. After I made that change, it worked, except for one thing: using C++ destructors to unload datafiles, remove timers, etc. is asking for trouble. Don't do it. If you do do it, make sure that instances of the class are destroyed before Allegro is shut down.
|
The Master
Member #4,498
April 2004
|
ok, cool. so you put this on your own compiler and it animated that little sprite? With the megaman animation? We can only do what we feel is right each moment as we live it. |
Peter Wang
Member #23
April 2000
|
I don't remember it animating, but at least there was a sprite there :-)
|
The Master
Member #4,498
April 2004
|
just out of curiosity, how would you recommend i use (vector).push_back()? Pointer to the data, or the actual data? We can only do what we feel is right each moment as we live it. |
BAF
Member #2,981
December 2002
|
Pointer. |
The Master
Member #4,498
April 2004
|
I've made the adjustments, however, there must be a problem with how the information is stored in the vector for anim_t. I am certain RLE_SPRITE works fine, however the vector that holds all information (including the RLE_SPRITE information) must not be stored properly. I have added a little debugging dump function which prints out the names of the animations in the anim_t vector, and it shows stuff like:
You see what I mean?
If you need to see the rest of the code it is has been updated, and is here: If there is anything more i should change, please let me know. cheers, and I'll put your name in the credits. We can only do what we feel is right each moment as we live it. |
Thomas Fjellstrom
Member #476
June 2000
|
Quote: animation.anim_data.push_back( get_rle_sprite( create_sub_bitmap( (BITMAP*)d->dat, x*animation.w, 0, animation.w, animation.h ) ) ); Holy memory leak batman as for the name problem.. what does your animation class/struct look like? is "name" allocated some space, statically, dynamically? edit: I looked at your source, oddly I didn't see anything interesting, but you may want to check to see if you're overwriting some memory somewhere.. -- |
Evert
Member #794
November 2000
|
As an aside, since this doesn't seem to be a problem with Allegro, could a friendly moderator move the topic to programming questions? |
The Master
Member #4,498
April 2004
|
OK, let me take some time to explain the logic behind some of my programming decisions: Quote: animation.anim_data.push_back( get_rle_sprite( create_sub_bitmap( (BITMAP*)d->dat, x*animation.w, 0, animation.w, animation.h ) ) ); Holy memory leak batman I know this is a dodgy memory leak. However, if I created a variable for the bitmap and the rle sprite, get the sub-bitmap, get the rle sprite from the sub-bitmap, and then add it to the RLE_SPRITE vector, it would store a pointer to the data right? If i were to reuse the rle_sprite or bitmap variables again, changing the data they contain, i would also be changing the data that would be percieved from reading the vector later on, would I not? If the vector contains pointers to the data and not actually the data itself, that is. Even still, destroying RLE_SPRITE or BITMAP structures inside a loop would be a bad idea as I'd have runtime exceptions all over the place. So as to avoid screwing up the information later on, I chose to do this as there would be no variables i would need to clear or destroy in a for loop or while loop (see the code). I have also considered using malloc instead of a vector for the RLE_SPRITE array, and even experimented with ZERO_SIZE_ARRAY, but when the program tries to read the information from the array, it returns a null reference exeption, always at the same place in the rle.inl file. I know it has no problem with Allegro, the pointers are just screwey in MY code. I don't think the malloc function works properly on my computer. Quote: I looked at your source, oddly I didn't see anything interesting, but you may want to check to see if you're overwriting some memory somewhere.. I just wanted to check if it is a bad idea to use a vector within a vector, like i've done. if so, would it be better to make the memory read-only after loading, to prevent any screw-ups? Is that even possible? Quote: As an aside, since this doesn't seem to be a problem with Allegro, could a friendly moderator move the topic to programming questions? I agree this isn't a problem with Allegro, however, RLE_SPRITE structures have never been very cooperative with me, and i was wondering if anyone else had ever had this problem. But, Mr.Moderator, by all means move this wherever you like. I'm just after the answers. Quote: as for the name problem.. what does your animation class/struct look like? is "name" allocated some space, statically, dynamically? This is the anim_t struct for holding the sprite information: struct anim_t { char name[20]; int frame_speed; int frame_count; int xorigin, yorigin; int w, h; std::vector<RLE_SPRITE*> anim_data; }; As you can see, name is a set 20 character long string. All the rest are integers except for the anim_data. I would say that the vector storage of the RLE_SPRITE works. However, when the entire anim_t structure is written into the animation vector, a problem occurs. Either that or the whole thing screws up from the start at which point i would need to start writing the loading code from scratch, which makes up the bulk of the class. But hey, if I must, I must. Just for the sake of explanation, i am incredibly bad at producing optimised code, and pretty much a hobbyist programmer. I've very little idea of how any of these things work except what I read in tutorials, and those ones only deal with integer and char vectors. I know how to use vectors, however this has never come up before. We can only do what we feel is right each moment as we live it. |
|