Go to Post I will follow FIRST's guidelines, as long as they conform with those of the English language. - artdutra04 [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:52.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi