|
Strange problem |
Steve Terry
Member #1,989
March 2002
|
I have an animation that I'm pushing into a vector and updating upon the Update() method. Problem is that if I put the code in one class it works fine and all frames are played, if I move it into a different class I only get one frame and other strange errors. Works: typedef struct BlockTile { unsigned int x; unsigned int y; AnimTile tile; }BlockTile;
Doesn't work:
I'm trying to make all blocks that are scanned play the animation but for now I'm just trying to get the clicked tile to work. I can't see why the two implementations would cause different results. I've even tried just simply calling j->tile.Update() and in isActive() returning true always so that the Game class doesn't kill the scan when it is complete but I still only get the first frame of the animation in BlockScan whereas in Game I get all frames. ___________________________________ |
Thomas Fjellstrom
Member #476
June 2000
|
Bump... -- |
Steve Terry
Member #1,989
March 2002
|
I got it fixed, basically I just needed to use pointers rather than the default copy method which seemed to break things. Once I wrote my own copy constructor and used new and delete things worked smoothly. For those who are wondering what I'm working on here is a screenshot: I'll have a download link available before long. It's going to be a semi-clone of Mario vs Donkey Kong II only featuring Alex ___________________________________ |
Onewing
Member #6,152
August 2005
|
Quote: featuring Alex The alligator? ------------ |
LennyLen
Member #5,313
December 2004
|
Quote: The alligator? I thought he meant this Alex.
|
ImLeftFooted
Member #3,935
October 2003
|
Your update animations and update blocks for loops will skip the next element whenever you erase one. If you erase the last element that code should crash. You have to move the iterator increment out of the for statement and only execute it if you do not erase anything. |
Steve Terry
Member #1,989
March 2002
|
DDustin: What? Oh I see, I should check to make sure that j does not equal end or you will call update on an invalid element. Thanks. Actually I'm not sure that case will ever happen, it's in an else clause. ___________________________________ |
ImLeftFooted
Member #3,935
October 2003
|
Calling itr = list.erase(itr); is effectively the same as ++itr. Your for loop also executes ++itr, resulting (in cases where an erase occurs) in ++itr being executed twice. If you erased the last element, you will ++ your way past list.end() and your loop will continue iterating infinitely (although your compiler may project you from this). Even if its not the last element, you're still skipping the element just after the one you erased, since you've incremented your iterator twice. |
Steve Terry
Member #1,989
March 2002
|
What would be a good solution to this? ___________________________________ |
Jonatan Hedborg
Member #4,886
July 2004
|
if( doErase ) theIter = list.erase(theIter) else theIter++; Oslt.
|
Steve Terry
Member #1,989
March 2002
|
Thanks. ___________________________________ |
|