class LuminaireProbability
{
public:
LuminaireProbability() : mIntersectable(0),mMaterial(0),mLuminaireProbabilityValue(0.0f),
mCumulativeDistributionValue(0.0f)
{
}
~LuminaireProbability()
{
mIntersectable = 0;
mMaterial = 0;
}
//luminaire as an intersectable
Intersectable *mIntersectable;
//material of the intersectable
Material *mMaterial;
//probability of choosing the luminaire
float mLuminaireProbabilityValue;
//cumulative distribution value
float mCumulativeDistributionValue;
};
//the area light contains the reference
//to the geometric object to be the light source
//the geometric object in turn contains the emissive material
//thus providing the illumination
//in this way the type of geometric object automatically determines
//the type of light, in principle it allows any type of the geometric
//object to be a light source
//SOME OF THE ABOVE STATEMENTS DEMANS CHANGE
std::vector<LuminaireProbability*> mLightIntersectables;
//store the selected lumianire from the vector
LuminaireProbability *mSelectedLuminaire;
I have the std::vector populated with a pointer of intersectables of type triangle or sphere along with some other trivial information. Now i have the following function
//calcualate the world position based on the intersection point
bool AreaLight::calculateSampleDirection(const Intersection &intersection,Vector3D &sampleVector)
{
//choose the light intersectables based on the weight of the probaiblity
//that we have calculated in the prepare() function
float selectionProbability = 0.0f;
//create a random instance
RandomGenerator random = RandomGenerator::getRandomInstance();
//create a canonical random number between 0 and 1
selectionProbability = static_cast<float>(random.generateDouble(0,1));
CompareToCDF cdf;
//store the canonical random value
cdf.mRandomValue = selectionProbability;
// CompareAreaLight cmpAreaLight;
// //sort the light intersectables based on the luminaire probability value
// std::sort(mLightIntersectables.begin(),mLightIntersectables.end(),cmpAreaLight);
std::vector<LuminaireProbability*>::iterator it;
it = std::find_if(mLightIntersectables.begin(),mLightIntersectables.end(),cdf);
assert(it != mLightIntersectables.end());
//store the selected luminaire
mSelectedLuminaire = *it;
//I AM GETTING A SEGMENTATION FAULT IN THE FOLLOWING FUNCTION - !!!!!
mSelectedLuminaire->mIntersectable->sampleDirection(intersection,sampleVector);
returntrue;
}
As mentioned in the code i am getting the segmentation fault that the debugger is not even giving any hint of.
I hope you will be able to help me find out the issue here that i am missing.
Is there any logical mistake i am doing here?
Obviously you have a pretty complex program here, so it would be difficult if not impossible for anyone to diagnose the issue with only what you gave us. But if I had to guess, I would say that since your constructor sets all of your pointers to 0 that one of the objects being referenced is still pointing to a NULL value. Maybe temporarily try something like:
(gdb) backtrace
#0 0x2efd85ba in ?? ()
#1 0x0804e018 in AreaLight::calculateSampleDirection (this=0x80c4d60,
intersection=..., sampleVector=...) at arealight.cpp:151
#2 0x080556ed in Intersection::getShadowRay (this=0xbfffedfc, light=0x80c4d60)
at intersection.cpp:152
#3 0x08069787 in PathTracer::computeDirectIllumination (this=0xbffff220,
intersection=...) at pathtracer.cpp:179
#4 0x0806a3df in PathTracer::computeRadiance (this=0xbffff220,
intersection=..., depth=5) at pathtracer.cpp:141
#5 0x0806a63f in PathTracer::trace (this=0xbffff220, ray=..., E=1)
at pathtracer.cpp:127
#6 0x0806a8e0 in PathTracer::tracePixel (this=0xbffff220, x=0, y=1)
at pathtracer.cpp:95
#7 0x0806aa14 in PathTracer::computeImage() [clone ._omp_fn.0] ()
at pathtracer.cpp:53
#8 0x0806ac46 in PathTracer::computeImage (this=0xbffff220)
at pathtracer.cpp:47
#9 0x0804c397 in main (argc=1, argv=0xbffff304) at main.cpp:504
(gdb)
Please let me know if there is any more information i can provide you with to help me get around with this issue.
Are you using multiple threads or am I reading that wrong? Maybe something is over-writing\deleting one of your const references while another thread is trying to use it?