[fixed]array erase() auto sorting?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

[fixed]array erase() auto sorting?

Post by Virion »

i've found out a problem when using array, which is for example I stored some scene nodes in an array, and would like to delete some of it later using for-loop

Code: Select all

nodeList[i]->remove();
nodeList.erase(i);
I realize scene nodes that are in the end of the list didn't get deleted. i think array auto sorted the list when i use erase(), bringing the elements at the back in-front to fill in the blank am I correct?

I don't want to do that I want to manually sort() the list after I done my removals. Any way to do that? Thanks.
Last edited by Virion on Sun Feb 14, 2010 9:57 pm, edited 1 time in total.
vins
Posts: 51
Joined: Mon Aug 16, 2004 6:14 pm
Location: Sofia, Bulgaria
Contact:

Post by vins »

Does deleting from big to lower index helps?
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post by Nox »

:? your approach is a bit strange. If you erase something from a container it will be delete. The container just rearrange all elements. That correct. Thats not really a sort. Its more a shift operation. There is no way to "mark" some of the elements and delete it later in one big call. The only way i now is to use another container putting the kept elements in and swap the contents of the container later.
Zeus
Posts: 24
Joined: Sun Dec 13, 2009 1:03 pm
Location: Germany :P

Post by Zeus »

or you could write your own container ...
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

nevermind... i cleared the array and re-add all scene nodes into the list again after deleted the unwanted scene nodes. i know, it's a bit strange but this is the only way that works for me now.

p/s. i don't know why but the reverse order just doesn't work it crashes.
Post Reply