View Single Post
  #4   Spotlight this post!  
Unread 27-03-2012, 19:59
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 157
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: cRIO FRC_RobotTask error

I agree - most likely the use of a null pointer. As a general rule of C/C++ programming, this is a MUST -- check all pointers before using them. **ALSO** if you 'delete' a pointer, set that pointer to NULL afterwards as well. The programming is a little more 'verbose', but it is SAFER. Crashing in a real-time robot is the PITS.

For instance: (Writing a sample that should be rather 'real' but is from memory so may come with issues...this is intended to show the use of pointer checking -- not syntax and running code)

Code:
ColorImage* pImage;
pImage = NULL;
AxisCamera& cam=AxisCamera::GetInstance();
BinaryImage* pBin;
pBin = NULL;

while(IsOperatorControl())
{
  if (cam.IsFreshImage())
  {
    pImage = cam.GetImage();
    if (pImage)
    {
      pBin = pImage->ThresholdHSL(x,y,z,zz,p,d,NULL);
      if (pBin)
      {
        // Do something using pBin like particle report ...
      }
      else
        printf("ERROR: ThresholdHSL() failed.\n");
    }
    else
      printf("ERROR: GetImage() failed.\n");

    // Done with the image -- must dispose of it.
    // But *SHOULD* also reset it to NULL so it doesn't get used accidentally.
    if (pImage)
    {
      delete pImage;
      pImage = NULL;
    }

    // Done with the image -- must dispose of it.
    // But *SHOULD* also reset it to NULL so it doesn't get used accidentally.
    if (pBin)
    {
      delete pBin;
      pBin = NULL;
    }
  }
}
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote