CVertexBuffer and CIndexBuffer use shallow copies

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
Vandar_Vegawan
Posts: 3
Joined: Wed Mar 28, 2012 10:50 pm

CVertexBuffer and CIndexBuffer use shallow copies

Post by Vandar_Vegawan »

CVertexBuffer and CIndexBuffer both define no copy constructor or assignment operator, and thus use the compiler's default one. Because they allocate their own memory, this leads to segmentation faults when you try to delete copied instances or place them into STL containers which depend on those routines.

Example failure code:

Code: Select all

 
// CVertexBuffer and CIndexBuffer copy constructor test
#include <irrlicht.h>
 
int main()
{
    irr::scene::CVertexBuffer cvb1(irr::video::EVT_STANDARD);
    //irr::scene::CVertexBuffer cvb2(cvb1); //< shallow copy leads to seg fault on deletion!
    irr::scene::CVertexBuffer cvb2(irr::video::EVT_STANDARD);
    //cvb2 = cvb1; //< shallow copy
 
    irr::scene::CIndexBuffer cib1(irr::video::EIT_16BIT);
    //irr::scene::CIndexBuffer cib2(cib1); //< shallow copy
    irr::scene::CIndexBuffer cib2(irr::video::EIT_16BIT);
    //cib2 = cib1; //< shallow copy
 
    return 0;
}
 
Both classes contain a constructor to copy from their base class, whose implementation can be duplicated in the necessary functions. Alternatively, if copying is not supposed to be an intended feature, the copy constructor and assignment operator could be made private so problems will be caught at compile time.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: CVertexBuffer and CIndexBuffer use shallow copies

Post by REDDemon »

I thought that irr::array was using a deep copy O_O
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:

Re: CVertexBuffer and CIndexBuffer use shallow copies

Post by CuteAlien »

Yeah, private copy constructor and assignment operators are missing in Irrlicht so far. For copying some classes have clone() functions, but even there some are not complete I think (probably because sometimes it's really hard to tell if a sub-object should be copied or the reference should be copied).
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
Post Reply