Unhandled exception at 0x010A85FB in ray tracer.exe: 0xC0000005: Access violation writing location 0x709DF990
<p>I have been trying to get rid of this error but nothing seems to work. I am coding in C++ in Visual Studio 2012, using OpenGL. Here I initialize the <code>rtScene</code> object, the default constructor of this object reads a file and sets the other data member values. 
The error pops up when I make the call to function <code>SphereSet()</code>, which sets the values of data members of sphere using respective functions of data members. </p>

<pre><code>class rtPoint
{
    friend class Sphere;
    friend class rtScene;
private:
    double xx,yy,zz;
public:
    rtPoint():xx(0),yy(0),zz(0){cout&lt;&lt;"vi";};
    void rtPointSet(double x,double y,double z)
    {
        xx=x;yy=y;zz=z;
        //cout&lt;&lt;xx&lt;&lt;" "&lt;&lt;yy&lt;&lt;" "&lt;&lt;zz&lt;&lt;"\n";
    }
    void rtPointSet(rtPoint p)
    {
        xx=p.xx;
        yy=p.yy;
        zz=p.zz;
    }
};

class Sphere
{
    friend class rtScene;
private:
    rtPoint center;
    double radius;
    color3 color;
    Material surface;
public:
    Sphere():center(),radius(1),color(),surface(){};
    void SphereSet(double x,double y,double z,double r,
                   double rr,double gg,double bb,double Par,
                   double Pag,double Pab, double Pdr, double Pdg, 
                   double Pdb,double Psr,double Psg,double Psb,double PhCo)
    {
        center.rtPointSet(x,y,z);
        color.set(rr,gg,bb);
        radius=r;
        surface.MaterialSet(Par, Pag, Pab, Pdr, Pdg, Pdb, Psr, Psg, Psb, PhCo);
    }
};

class rtScene
{
private:
    Sphere *Sph_obj;
    //Sphere Sph_obj[3];
    int nS,nL;
    rtCamera CAM;
    rtLight *Lights;
public:
    rtScene(char *fname)
    {
        FILE *fp;
        fp=fopen(fname,"r");
        double a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q;
        char ch;

        //.........read camera.........//
        fscanf(fp,"%lf,%lf,%lf,%lf,%lf,%lf\n",&amp;a,&amp;b,&amp;c,&amp;d,&amp;e,&amp;f);                   // 6 values
        this-&gt;CAM.rtCameraWindow(a,b,c,d,e,f);
        fscanf(fp,"%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",&amp;a,&amp;b,&amp;c,&amp;d,&amp;e,&amp;f,&amp;g,&amp;h,&amp;i);  // 9 values
        this-&gt;CAM.rtCameraSet(a,b,c,d,e,f,g,h,i);
        //.............................//

        //.......read Lights.............//
        fscanf(fp,"%c %d\n",&amp;ch,&amp;nL);
        cout&lt;&lt;nL;
        if(ch=='l')
        {
            this-&gt;Lights=new rtLight[nL];
            for(int i=0;i&lt;nL;i++)
            {
                fscanf(fp,"%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",&amp;a,&amp;b,&amp;c,&amp;d,&amp;e,&amp;f,&amp;g,&amp;h,&amp;i,&amp;j,&amp;k,&amp;l); //12 values
                this-&gt;Lights[i].rtLightSet(a,b,c,d,e,f,g,h,i,j,k,l);
            }
        }
        //..............................//

        //.....read spheres.............//
        fscanf(fp,"%c %d\n",&amp;ch,&amp;nS);
        cout&lt;&lt;nS;
        if(ch=='s')
        {
            this-&gt;Sph_obj=new Sphere[nS];
            //Sph_obj=(class Sphere *) malloc(sizeof(Sphere)*nS);
            for(int i=0;i&lt;nS;i++)
            {
                fscanf(fp,"%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",&amp;a,&amp;b,&amp;c,&amp;d,&amp;e,&amp;f,&amp;g,&amp;h,&amp;i,&amp;j,&amp;k,&amp;l,&amp;m,&amp;n,&amp;o,&amp;p,&amp;q);
                this-&gt;Sph_obj[i].SphereSet(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q);
            }
        }
        //.............................//
    }
};
</code></pre>

<p>code crashes giving the error "First-chance exception at 0x010A85FB in ray tracer.exe: 0xC0000005: Access violation writing location 0x709DF990" when function <code>rtPointSet</code> tries to set the <code>xx</code>, <code>yy</code>, <code>zz</code> value for center variable of Sphere. </p>
