We all know how at some point a small typo can result in odd application behavior even if the source code it self compiles. One issue that pops up from time to time is missing the ‘&’ character and thus declaring a variable inadvertently as not being a reference.
RRArray<RRInt_t> rIndices = pSubMesh->GetIndices();
Just recently I ran into this kind of a situation where I had a method that contained this kind of an invalid variable definition (GetIndices returns a reference to an instance of RRArray<RRInt_t>). The bug was actually quite hard to track down, since problems popped up only after the object referenced by pSubMesh was destructed.
First of all I had not explicitly defined a copy constructor for RRArray. This meant that the default copy constructor just copied the internal array pointer to the new instance. When the scope of rIndices was left the object’s internal memory was released. When the array object owned by the sub mesh was destructed, however, that same internal memory had already been released.
This doesn’t happen that often but when it does, it’s quite hard to spot it as the problem might seem quite disjoint from it’s consequences.