News

My Stats

  • Posts - 21
  • Comments - 20
  • Trackbacks - 0

Twitter












Recent Comments


Recent Posts


Archives


Post Categories



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.

void SomeMethod()
{
    // ...

    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.


Comments

Gravatar # re: Referential danger
Posted by Rickey Fain on 5/26/2011 2:17 PM
The Mariner 1 is probably the best example of how small mistakes in coding can have huge consequences.
Gravatar # re: Referential danger
Posted by Mandy More on 5/14/2012 1:05 PM
No matter how good you are at it all wrong from time to time. Especially when you write code in a notepad is most evident.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: