Program: 35160
Project: 35160
Buggy source:
@Override protected synchronized Object doInBackground() throws Exception {
  try {
    setProgress(INITIALIZING);
    frameGrabber=cameraDevice.createFrameGrabber();
    frameGrabber.setImageMode(ImageMode.COLOR);
    if (trackingSettings.useOpenCL) {
      frameGrabber.setPixelFormat(PIX_FMT_RGBA);
    }
    frameGrabber.start();
    IplImage image=frameGrabber.grab();
    final IplImage initImage=image;
    final int initWidth=initImage.width();
    final int initHeight=initImage.height();
    final int initChannels=trackingSettings.useOpenCL ? 4 : initImage.nChannels();
    final int initDepth=initImage.depth();
    if (initWidth != cameraDevice.imageWidth || initHeight != cameraDevice.imageHeight) {
      cameraDevice.rescale(initWidth,initHeight);
    }
    if (monitorWindows != null) {
      final double initScale=trackingSettings.getMonitorWindowsScale();
      EventQueue.invokeLater(new Runnable(){
        public void run(){
          for (int i=0; i < monitorWindows.length; i++) {
            monitorWindows[i].setCanvasSize((int)Math.round(initWidth * initScale),(int)Math.round(initHeight * initScale));
            monitorWindows[i].setTitle(monitorWindowsTitles[i] + "String_Node_Str" + initWidth+ "String_Node_Str"+ initHeight+ "String_Node_Str"+ (initDepth & ~IPL_DEPTH_SIGN)+ "String_Node_Str"+ frameGrabber.getGamma()+ "String_Node_Str");
          }
        }
      }
);
      CanvasFrame.tile(monitorWindows);
      CanvasFrame.global=monitorWindows[0];
    }
    final int minLevel=alignerSettings.getPyramidLevelMin();
    undistortedCameraImage=IplImage.create(initWidth >> minLevel,initHeight >> minLevel,initDepth,initChannels);
    distortedProjectorImage=IplImage.create(projectorDevice.imageWidth,projectorDevice.imageHeight,IPL_DEPTH_8U,initChannels);
    BufferRing.BufferFactory<ProjectorBuffer> projectorBufferFactory;
    projectorBufferFactory=new BufferRing.BufferFactory<ProjectorBuffer>(){
      public ProjectorBuffer create(){
        return new ProjectorBuffer(distortedProjectorImage,false);
      }
    }
;
    if (trackingSettings.useOpenCL) {
      GLContext shareWith=null;
      if (projectorFrame instanceof GLCanvasFrame) {
        shareWith=((GLCanvasFrame)projectorFrame).getGLCanvas().getContext();
      }
      contextCL=new JavaCVCL(shareWith);
      grabbedImageCL=contextCL.getCLContext().createImage2d(initWidth,initHeight,new CLImageFormat(frameGrabber.getSensorPattern() != -1L ? CLImageFormat.ChannelOrder.R : CLImageFormat.ChannelOrder.RGBA,ChannelType.UNORM_INT8));
      undistortedCameraImageCL=contextCL.getCLContext().createImage2d(undistortedCameraImage.width(),undistortedCameraImage.height(),new CLImageFormat(CLImageFormat.ChannelOrder.RGBA,ChannelType.FLOAT));
      cameraDevice.setMapsPyramidLevel(minLevel);
      cameraMapxCL=contextCL.writeImage(cameraMapxCL,cameraDevice.getUndistortMap1(),false);
      cameraMapyCL=contextCL.writeImage(cameraMapyCL,cameraDevice.getUndistortMap2(),false);
      if (projectorFrame != null) {
        projectorMapxCL=contextCL.writeImage(projectorMapxCL,projectorDevice.getDistortMap1(),false);
        projectorMapyCL=contextCL.writeImage(projectorMapyCL,projectorDevice.getDistortMap2(),false);
        distortedProjectorImageCL=contextCL.createCLGLImageFrom(distortedProjectorImage);
      }
      projectorBufferFactory=new BufferRing.BufferFactory<ProjectorBuffer>(){
        public ProjectorBuffer create(){
          return new ProjectorBuffer(distortedProjectorImage,true);
        }
      }
;
    }
    projectorBufferRing=new BufferRing<ProjectorBuffer>(projectorBufferFactory,trackingSettings.projectorBufferingSize);
    realityAugmentor=new RealityAugmentor(realityAugmentorSettings,objectFinderSettings,markerDetectorSettings,virtualBallSettings,cameraDevice,projectorDevice,initChannels);
    handMouse=new HandMouse(handMouseSettings);
    GNImageAligner.Settings s=alignerSettings.clone();
    s.setAlphaTikhonov(0);
    s.setDeltaMin(0);
    s.setLineSearch(new double[]{1.0,1.0 / 2,1.0 / 4,1.0 / 8,1.0 / 16,1.0 / 32,1.0 / 64,1.0 / 128});
    s.setThresholdsOutlier(new double[]{0.0});
    s.setThresholdsZero(new double[]{0.0});
    reflectanceInitializer=new ReflectanceInitializer(cameraDevice,projectorDevice,initChannels,s);
    projectorInitFloatImages=reflectanceInitializer.getProjectorImages();
    projectorInitImages=new IplImage[projectorInitFloatImages.length];
    cameraInitImages=new IplImage[projectorInitFloatImages.length];
    cameraInitFloatImages=new IplImage[projectorInitFloatImages.length];
    for (int i=0; i < projectorInitFloatImages.length; i++) {
      projectorInitImages[i]=IplImage.createCompatible(distortedProjectorImage);
      cameraInitImages[i]=IplImage.create(initWidth,initHeight,initDepth,initChannels);
      cameraInitFloatImages[i]=IplImage.create(undistortedCameraImage.width(),undistortedCameraImage.height(),IPL_DEPTH_32F,initChannels);
      cvConvertScale(projectorInitFloatImages[i],projectorInitImages[i],255,0);
      projectorDevice.distort(projectorInitImages[i],distortedProjectorImage);
      cvCopy(distortedProjectorImage,projectorInitImages[i]);
    }
    reflectanceImage=IplImage.createCompatible(cameraInitFloatImages[0]);
    if (trackingSettings.useOpenCL) {
      reflectanceImageCL=contextCL.createCLImageFrom(reflectanceImage);
    }
    if (trackingSettings.outputVideoFile != null) {
      frameRecorder=new FFmpegFrameRecorder(trackingSettings.outputVideoFile,undistortedCameraImage.width(),undistortedCameraImage.height());
      frameRecorder.start();
    }
 else {
      frameRecorder=null;
    }
    boolean done=false;
    while (!done) {
      done=doTracking();
      System.gc();
      Pointer.deallocateReferences();
    }
  }
 catch (  Throwable t) {
    if (!isCancelled()) {
      while (t.getCause() != null) {
        t=t.getCause();
      }
      logger.log(Level.SEVERE,"String_Node_Str",t);
      cancel(false);
    }
  }
  try {
    if (frameGrabber != null) {
      frameGrabber.stop();
      frameGrabber.release();
    }
  }
 catch (  Exception ex) {
    logger.log(Level.SEVERE,"String_Node_Str",ex);
  }
 finally {
    frameGrabber=null;
  }
  try {
    if (frameRecorder != null) {
      frameRecorder.stop();
      frameRecorder.release();
    }
  }
 catch (  Exception ex) {
    logger.log(Level.SEVERE,"String_Node_Str",ex);
  }
 finally {
    frameRecorder=null;
  }
  if (trackingSettings.useOpenCL) {
    grabbedImageCL.release();
    undistortedCameraImageCL.release();
    contextCL.releaseCLGLImage(distortedProjectorImageCL);
    reflectanceImageCL.release();
    cameraMapxCL.release();
    cameraMapyCL.release();
    projectorMapxCL.release();
    projectorMapyCL.release();
    grabbedImageCL=undistortedCameraImageCL=distortedProjectorImageCL=null;
    reflectanceImageCL=null;
    cameraMapxCL=cameraMapyCL=projectorMapxCL=projectorMapyCL=null;
    contextCL.release();
    contextCL=null;
  }
  roiPts=null;
  transformer=null;
  parameters=lastParameters=tempParameters=null;
  aligner=null;
  reflectanceInitializer=null;
  handMouse=null;
  realityAugmentor=null;
  grabbedImage=undistortedCameraImage=distortedProjectorImage=null;
  projectorInitFloatImages=projectorInitImages=null;
  cameraInitImages=cameraInitFloatImages=monitorImages=null;
  reflectanceImage=null;
  projectorBufferRing.release();
  projectorBufferRing=null;
  System.gc();
  Pointer.deallocateReferences();
  return null;
}

Fixed version (ground truth):
@Override protected synchronized Object doInBackground() throws Exception {
  try {
    setProgress(INITIALIZING);
    frameGrabber=cameraDevice.createFrameGrabber();
    frameGrabber.setImageMode(ImageMode.COLOR);
    if (trackingSettings.useOpenCL) {
      frameGrabber.setPixelFormat(AV_PIX_FMT_RGBA);
    }
    frameGrabber.start();
    IplImage image=frameGrabber.grab();
    final IplImage initImage=image;
    final int initWidth=initImage.width();
    final int initHeight=initImage.height();
    final int initChannels=trackingSettings.useOpenCL ? 4 : initImage.nChannels();
    final int initDepth=initImage.depth();
    if (initWidth != cameraDevice.imageWidth || initHeight != cameraDevice.imageHeight) {
      cameraDevice.rescale(initWidth,initHeight);
    }
    if (monitorWindows != null) {
      final double initScale=trackingSettings.getMonitorWindowsScale();
      EventQueue.invokeLater(new Runnable(){
        public void run(){
          for (int i=0; i < monitorWindows.length; i++) {
            monitorWindows[i].setCanvasSize((int)Math.round(initWidth * initScale),(int)Math.round(initHeight * initScale));
            monitorWindows[i].setTitle(monitorWindowsTitles[i] + "String_Node_Str" + initWidth+ "String_Node_Str"+ initHeight+ "String_Node_Str"+ (initDepth & ~IPL_DEPTH_SIGN)+ "String_Node_Str"+ frameGrabber.getGamma()+ "String_Node_Str");
          }
        }
      }
);
      CanvasFrame.tile(monitorWindows);
      CanvasFrame.global=monitorWindows[0];
    }
    final int minLevel=alignerSettings.getPyramidLevelMin();
    undistortedCameraImage=IplImage.create(initWidth >> minLevel,initHeight >> minLevel,initDepth,initChannels);
    distortedProjectorImage=IplImage.create(projectorDevice.imageWidth,projectorDevice.imageHeight,IPL_DEPTH_8U,initChannels);
    BufferRing.BufferFactory<ProjectorBuffer> projectorBufferFactory;
    projectorBufferFactory=new BufferRing.BufferFactory<ProjectorBuffer>(){
      public ProjectorBuffer create(){
        return new ProjectorBuffer(distortedProjectorImage,false);
      }
    }
;
    if (trackingSettings.useOpenCL) {
      GLContext shareWith=null;
      if (projectorFrame instanceof GLCanvasFrame) {
        shareWith=((GLCanvasFrame)projectorFrame).getGLCanvas().getContext();
      }
      contextCL=new JavaCVCL(shareWith);
      grabbedImageCL=contextCL.getCLContext().createImage2d(initWidth,initHeight,new CLImageFormat(frameGrabber.getSensorPattern() != -1L ? CLImageFormat.ChannelOrder.R : CLImageFormat.ChannelOrder.RGBA,ChannelType.UNORM_INT8));
      undistortedCameraImageCL=contextCL.getCLContext().createImage2d(undistortedCameraImage.width(),undistortedCameraImage.height(),new CLImageFormat(CLImageFormat.ChannelOrder.RGBA,ChannelType.FLOAT));
      cameraDevice.setMapsPyramidLevel(minLevel);
      cameraMapxCL=contextCL.writeImage(cameraMapxCL,cameraDevice.getUndistortMap1(),false);
      cameraMapyCL=contextCL.writeImage(cameraMapyCL,cameraDevice.getUndistortMap2(),false);
      if (projectorFrame != null) {
        projectorMapxCL=contextCL.writeImage(projectorMapxCL,projectorDevice.getDistortMap1(),false);
        projectorMapyCL=contextCL.writeImage(projectorMapyCL,projectorDevice.getDistortMap2(),false);
        distortedProjectorImageCL=contextCL.createCLGLImageFrom(distortedProjectorImage);
      }
      projectorBufferFactory=new BufferRing.BufferFactory<ProjectorBuffer>(){
        public ProjectorBuffer create(){
          return new ProjectorBuffer(distortedProjectorImage,true);
        }
      }
;
    }
    projectorBufferRing=new BufferRing<ProjectorBuffer>(projectorBufferFactory,trackingSettings.projectorBufferingSize);
    realityAugmentor=new RealityAugmentor(realityAugmentorSettings,objectFinderSettings,markerDetectorSettings,virtualBallSettings,cameraDevice,projectorDevice,initChannels);
    handMouse=new HandMouse(handMouseSettings);
    GNImageAligner.Settings s=alignerSettings.clone();
    s.setAlphaTikhonov(0);
    s.setDeltaMin(0);
    s.setLineSearch(new double[]{1.0,1.0 / 2,1.0 / 4,1.0 / 8,1.0 / 16,1.0 / 32,1.0 / 64,1.0 / 128});
    s.setThresholdsOutlier(new double[]{0.0});
    s.setThresholdsZero(new double[]{0.0});
    reflectanceInitializer=new ReflectanceInitializer(cameraDevice,projectorDevice,initChannels,s);
    projectorInitFloatImages=reflectanceInitializer.getProjectorImages();
    projectorInitImages=new IplImage[projectorInitFloatImages.length];
    cameraInitImages=new IplImage[projectorInitFloatImages.length];
    cameraInitFloatImages=new IplImage[projectorInitFloatImages.length];
    for (int i=0; i < projectorInitFloatImages.length; i++) {
      projectorInitImages[i]=IplImage.createCompatible(distortedProjectorImage);
      cameraInitImages[i]=IplImage.create(initWidth,initHeight,initDepth,initChannels);
      cameraInitFloatImages[i]=IplImage.create(undistortedCameraImage.width(),undistortedCameraImage.height(),IPL_DEPTH_32F,initChannels);
      cvConvertScale(projectorInitFloatImages[i],projectorInitImages[i],255,0);
      projectorDevice.distort(projectorInitImages[i],distortedProjectorImage);
      cvCopy(distortedProjectorImage,projectorInitImages[i]);
    }
    reflectanceImage=IplImage.createCompatible(cameraInitFloatImages[0]);
    if (trackingSettings.useOpenCL) {
      reflectanceImageCL=contextCL.createCLImageFrom(reflectanceImage);
    }
    if (trackingSettings.outputVideoFile != null) {
      frameRecorder=new FFmpegFrameRecorder(trackingSettings.outputVideoFile,undistortedCameraImage.width(),undistortedCameraImage.height());
      frameRecorder.start();
    }
 else {
      frameRecorder=null;
    }
    boolean done=false;
    while (!done) {
      done=doTracking();
      System.gc();
      Pointer.deallocateReferences();
    }
  }
 catch (  Throwable t) {
    if (!isCancelled()) {
      while (t.getCause() != null) {
        t=t.getCause();
      }
      logger.log(Level.SEVERE,"String_Node_Str",t);
      cancel(false);
    }
  }
  try {
    if (frameGrabber != null) {
      frameGrabber.stop();
      frameGrabber.release();
    }
  }
 catch (  Exception ex) {
    logger.log(Level.SEVERE,"String_Node_Str",ex);
  }
 finally {
    frameGrabber=null;
  }
  try {
    if (frameRecorder != null) {
      frameRecorder.stop();
      frameRecorder.release();
    }
  }
 catch (  Exception ex) {
    logger.log(Level.SEVERE,"String_Node_Str",ex);
  }
 finally {
    frameRecorder=null;
  }
  if (trackingSettings.useOpenCL) {
    grabbedImageCL.release();
    undistortedCameraImageCL.release();
    contextCL.releaseCLGLImage(distortedProjectorImageCL);
    reflectanceImageCL.release();
    cameraMapxCL.release();
    cameraMapyCL.release();
    projectorMapxCL.release();
    projectorMapyCL.release();
    grabbedImageCL=undistortedCameraImageCL=distortedProjectorImageCL=null;
    reflectanceImageCL=null;
    cameraMapxCL=cameraMapyCL=projectorMapxCL=projectorMapyCL=null;
    contextCL.release();
    contextCL=null;
  }
  roiPts=null;
  transformer=null;
  parameters=lastParameters=tempParameters=null;
  aligner=null;
  reflectanceInitializer=null;
  handMouse=null;
  realityAugmentor=null;
  grabbedImage=undistortedCameraImage=distortedProjectorImage=null;
  projectorInitFloatImages=projectorInitImages=null;
  cameraInitImages=cameraInitFloatImages=monitorImages=null;
  reflectanceImage=null;
  projectorBufferRing.release();
  projectorBufferRing=null;
  System.gc();
  Pointer.deallocateReferences();
  return null;
}