Bug on image sink

From Wiki for iCub and Friends
Jump to: navigation, search

There is a possible bug in the image_sink program. In some cases the read of a port can return a null pointer, so the code must check it.

Old code:

 ImageOf<PixelRgb> *imgIn = portIn.read(true);
 ImageOf<PixelRgb>& imgOut = portOut.prepare();
 imgOut.copy(*imgIn);
 addCircle(imgOut, PixelRgb(0,128,128), ct, imgOut.height()/2, 10);
 ct++;
 if (ct==imgOut.width())
     ct=0;
 portOut.write();
 ...

New code:

 ImageOf<PixelRgb> *imgIn = portIn.read(true);
 if (imgIn!=0)
   {
       ImageOf<PixelRgb>& imgOut = portOut.prepare();
       imgOut.copy(*imgIn);
       addCircle(imgOut, PixelRgb(0,128,128), ct, imgOut.height()/2, 10);
       ct++;
       if (ct==imgOut.width())
           ct=0;
       portOut.write();
   }
 ...

The iCub repository has been update accordingly, so you can also update your local copy of the software.