irrList: CODE::BLOCKS const iterator

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

irrList: CODE::BLOCKS const iterator

Post by REDDemon »

I'm working on a portable solution for a simple game framework and i found a bug: When compiling irrlicht with codeblocks (gcc) in the irr::core::list<> class the gcc compiler recognize the "getLast()" iterator as a const iterator and the "erase" method cannot delete it since it accept only non-const interators for beign erased. I get an error at compile time.

here's the code to reproduce the bug:

Code: Select all


class myClass
{

irr::core::list<Item*> ItemList;

void method();

myClass(){};
~myClass(){};

}

...
myClass::method()
{
     ItemList.erase(ItemList.getLast());
}
I get the bug with:

irrlicht.1.7.2 compiling with CODE::BLOCKS(gcc)
irrlicht.1.8 compiling with CODE::BLOCKS(gcc)

With visual studio there are no problem and the code run smoothly (both the original code and the simplified code).

Any suggestion on how to obtain the same result (delete the last item in the list) with a different code for a temporary fix?

edit: the same appens when using "begin()" instead of "getLast()" and appens only under codeBlocks. I don't know why it works under visual studio.

Other code like:

Code: Select all


if(!ItemList.empty())
works well so i don't think i have linked something in the wrong way.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Post by REDDemon »

ok i found a way to avoid this:

Code: Select all

myClass::method() 
{
     irr::core::list<Item*>::Iterator it = ItemList.getLast(); 
     ItemList.erase(it); 
} 
this is not necessary doing that in VISUAL STUDIO, but both codes works well under visual studio so, instead of keeping the code that work only with VISUAL studio now i'll keep the code that work also with codeblocks.

maybe it's really a gcc/codeblocks bug?
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

The problem is not about const but that erase expects a reference to the iterator instead of just taking an iterator. And it can't create a reference to a return value. That's why it works using a variable. Not sure what VS does with this, I think the gcc complain is rather correct.

Interestingly it even has a comment "// suggest changing this to a const Iterator&", so I suppose you're not the first one to stumble upon this. The solution in STL is to use an Iterator (no reference at all), but it seems that can't be changed easily for irr at the moment because it does stuff like memory-releasing in the erase.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Post by REDDemon »

ok thanks.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Post Reply