[fixed]irr::list copy constructor and operator=

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
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

[fixed]irr::list copy constructor and operator=

Post by CuteAlien »

This is not necessarly a bug, but they work different than std::list so i thought i mention it. I think the std::list does not copy the nodes but only the elements of a list.
The difference can be seen in the following behaviour:

Code: Select all

    std::list<int> stdA;
    stdA.push_back(1);
    std::list<int> stdB(stdA);
    std::list<int> stdC;
    stdC = stdA;

    core::list<int> irrA;
    irrA.push_back(1);
    core::list<int> irrB(irrA);
    core::list<int> irrC;
    irrC = irrA;
core::list will crash in both cases in the destructor because after copying the list-nodes will be referenced by both lists.
I'd recommend changing it, but i'm not sure if there ain't already code in the engine expecting that behavior...
Last edited by CuteAlien on Fri May 23, 2008 8:55 pm, edited 1 time in total.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Yet another reason for Irrlicht to just use the Standard C++ Library.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Indeed there are already some bug reports in the SF tracker showing severe problems due to this copy constructor. Since Irrlicht containers are meant to replace STL containers they should copy the complete behavior.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Simple Bugfix in irrList.h:

Code: Select all

	//! Copy constructor
	list(const list<T>& other)
	{
		*this = other;
	}

    //! Assignement operator
	void operator=(const list<T>& other)
	{
        root = 0;
        last = 0;
        size = 0;

        SKListNode* node = other.root;
		while(node)
		{
		    push_back(node->element);
			node = node->next;
		}
	}
game
Posts: 13
Joined: Sun Jul 09, 2006 2:47 pm

Post by game »

I have a segmentation fault in the destructor when I want to use this class in my own class:

Code: Select all

typedef irr::core::array<irr::scene::IAnimatedMesh*> listM;
class arrayM
{
    public:
        arrayM(){is_init=false;}
        virtual ~arrayM(){}
        void init(irr::s32 x1,irr::s32 y1)
        {
            lm.empty();
            x=x1;
            y=y1;
            max=x*y;
            current=0;
            is_init=true;
        }
        void add_item(irr::scene::IAnimatedMesh* mesh)
        {
            if(is_init)
                lm.push_back(mesh);
        }
        irr::scene::IAnimatedMesh* get_item(irr::s32 x1,irr::s32 y1)
        {
            if(!is_init)
                return 0;
            return lm[((y1-1)*x+x1)];
        }
    private:
        listM lm;//le plus important

        irr::s32 x;
        irr::s32 y;
        irr::s32 max;
        irr::s32 current;

        bool is_init;
};
Is anybody can help me ? :?

I forgot an important information: i'm using this class in an array like this"arrayM arr[9]" else if it is not in an array there is no problem!
Post Reply