View Single Post
  #3   Spotlight this post!  
Unread 30-01-2012, 03:54
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: GetParticleAnalysisReport causes crash

If you take a look at the source code of GetParticleAnalysisReport:
Code:
/**
 * Get a single particle analysis report.
 * Get one (of possibly many) particle analysis reports for an image.
 * This version could be more efficient when copying many reports.
 * @param particleNumber Which particle analysis report to return.
 * @param par the selected particle analysis report
 */
void BinaryImage::GetParticleAnalysisReport(int particleNumber, ParticleAnalysisReport *par)
{
 int success;
 int numParticles = 0;
 success = imaqGetImageSize(m_imaqImage, &par->imageWidth, &par->imageHeight);
 wpi_setImaqErrorWithContext(success, "Error getting image size");
 if (StatusIsFatal())
  return;
 success = imaqCountParticles(m_imaqImage, 1, &numParticles);
 wpi_setImaqErrorWithContext(success, "Error counting particles");
 if (StatusIsFatal())
  return;
 if (particleNumber >= numParticles)
 {
  wpi_setWPIErrorWithContext(ParameterOutOfRange, "particleNumber");
  return;
 }
 par->particleIndex = particleNumber;
 // Don't bother measuring the rest of the particle if one fails
 bool good = ParticleMeasurement(particleNumber, IMAQ_MT_CENTER_OF_MASS_X, &par->center_mass_x);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_CENTER_OF_MASS_Y, &par->center_mass_y);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA, &par->particleArea);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_TOP, &par->boundingRect.top);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_LEFT, &par->boundingRect.left);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_HEIGHT, &par->boundingRect.height);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_BOUNDING_RECT_WIDTH, &par->boundingRect.width);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA_BY_IMAGE_AREA, &par->particleToImagePercent);
 good = good && ParticleMeasurement(particleNumber, IMAQ_MT_AREA_BY_PARTICLE_AND_HOLES_AREA, &par->particleQuality);
 if (good)
 {
  /* normalized position (-1 to 1) */
  par->center_mass_x_normalized = NormalizeFromRange(par->center_mass_x, par->imageWidth);
  par->center_mass_y_normalized = NormalizeFromRange(par->center_mass_y, par->imageHeight);
 }
}
You will see that the parameter par is a pointer to the particle analysis report. The code is expecting the pointer is pointing to something. But the code that called the function passed in an uninitialized ParticleAnalysisReport pointer. That will caused an exception for sure. Where did you copy this code from? It should have a line allocating/initializing the ParticleAnalysisReport before passing it to the function.
__________________
Reply With Quote