| Mindaugas Steponavicius (5) | |||
|
Hi, I'm a beginner c++ programmer and I tried to make a game, but there's one error that keeps popping up. Debug Assertion Failed! <...> line 256. I think that the problem is in this part of the code:
Could you check for anything I might have done wrong here? Thanks in advance :) | |||
|
|
|||
| Mindaugas Steponavicius (5) | |
| P. S. Iter is an iterator for a list of one of the classes' (Sprite) pointers. The list itself is called npc. | |
|
Last edited on
|
|
| Caligulaminus (171) | |
| If Iter is pointing to npc.begin(), wouldn't Iter-- be problem? | |
|
|
|
| Mindaugas Steponavicius (5) | |||
I just tried to update the code to:
That took care of the error, but the game itself just crashes. If there are no other mistakes here, I guess there must be a mistake somewhere else. Thanks anyway :) | |||
|
|
|||
| Caligulaminus (171) | |||
If Iter points to npc.begin() you do the following:
I think you should use list::erase() | |||
|
|
|||
| coder777 (2378) | |||
|
The problem is at the beginning. If it is at the beginning you remove the 'Sprite' and thus invalidate 'Iter'. Better would be something like that:
| |||
|
|
|||
| Mindaugas Steponavicius (5) | |
|
The last code worked like a charm :) Thanks a lot :) Perhaps you could also explain to a beginer, what's the difference between erase and remove? | |
|
|
|
| sohguanh (1236) | ||
The STL containers erase/remove methods remove elements. But if you use the STL algorithm remove, remove_if, I don't think they do removal.What the function return is a "marker" where everything before "marker" is retain and all else after are elements to be removed but they are not removed yet. You need one more step to call STL containers erase/remove methods to do actual removal. | ||
|
|
||
| coder777 (2378) | ||
erase() removes the object pointed to by the iterator and returns the next valid iterator. remove() removes all objects which equals to the object provided. It does not return anything See http://www.cplusplus.com/reference/stl/list/remove/ http://www.cplusplus.com/reference/stl/list/erase/ | ||
|
|
||
| Mindaugas Steponavicius (5) | |
| Thanks a lot :) | |
|
|
|