applebibo
asked on
Access violation, cannot read memory xxxxxxx
Hi, I recently encountered an access violation problem. In VC++, if I run it, the error code is "cannot read memory xxxxxxx"; in the debug mode, it will show "xxxxxxxx: access violation".
I found out that this exception happened when a function was called to a number of times -- I am not sure if it happened at the same number. But the function works and this only happens after a number of calls, which frustrates me. Please help me!
Here is the functions. drawSurface() is to generate a set of x and y coordinates, and for each set, use surfacePoint() to calculate the z value of that point, and draw it in drawSurface().
void CBSplineView::drawSurface( )
{
MyPoint* s=new MyPoint();
glColor3f(1.0,1.0,0.0);
std::vector<MyPoint*> stor,cal;
int i,j;
double u,v;
u=0.0;
for (i=0;i<cal.size();i++) delete cal[i];
cal.clear();
for (j=0;j<=NUMBER; j++)
{
v=(double)j/fNUMBER*n;
s=new MyPoint();
surfacePoint(u,v,1,s);
cal.push_back(s);
}
for (i=1; i<=NUMBER; i++)
{
u=(double)i/fNUMBER*m;
for (int k=0;k<stor.size();k++) delete stor[k];
stor.clear();
stor=cal;
v=0.0;
cal.clear();
s=new MyPoint();
surfacePoint(u,v,1,s);
cal.push_back(s);
for (j=1; j<=NUMBER; j++)
{
v=(double)j/fNUMBER*n;
glBegin(GL_POLYGON);
glVertex3f(stor[j-1]->x,st or[j-1]->y ,stor[j-1] ->z);
glVertex3f(stor[j]->x,stor [j]->y,sto r[j]->z);
s=new MyPoint();
surfacePoint(u,v,1,s);
cal.push_back(s);
glVertex3f(cal[j]->x,cal[j ]->y,cal[j ]->z);
glVertex3f(cal[j-1]->x,cal [j-1]->y,c al[j-1]->z );
glEnd();
}
}
for (i=0;i<cal.size();i++) delete cal[i];
for (int k=0;k<stor.size();k++) delete stor[k];
}
void CBSplineView::surfacePoint (double u, double v, int h, MyPoint* S)
{
int i,j,k,l;
double s,t,temp;
i=floor(u*h);
j=floor(v*h);
s=(u-floor(u))*h;
t=(v-floor(v))*h;
temp=0.0;
for (k=0;k<=m_p;k++)
{
for (l=0;l<=m_q;l++)
{
temp=temp+B(k,m_p,s)*B(l,m _q,t)*poin ts[(i+k)*( n*h+m_q)+j +l]->z; // WHEN AN ERROR OCCURS, THE PROGRAM STOPS AT THIS LINE.
}
}
S->x=u;
S->y=v;
S->z=temp;
}
I found out that this exception happened when a function was called to a number of times -- I am not sure if it happened at the same number. But the function works and this only happens after a number of calls, which frustrates me. Please help me!
Here is the functions. drawSurface() is to generate a set of x and y coordinates, and for each set, use surfacePoint() to calculate the z value of that point, and draw it in drawSurface().
void CBSplineView::drawSurface(
{
MyPoint* s=new MyPoint();
glColor3f(1.0,1.0,0.0);
std::vector<MyPoint*> stor,cal;
int i,j;
double u,v;
u=0.0;
for (i=0;i<cal.size();i++) delete cal[i];
cal.clear();
for (j=0;j<=NUMBER; j++)
{
v=(double)j/fNUMBER*n;
s=new MyPoint();
surfacePoint(u,v,1,s);
cal.push_back(s);
}
for (i=1; i<=NUMBER; i++)
{
u=(double)i/fNUMBER*m;
for (int k=0;k<stor.size();k++) delete stor[k];
stor.clear();
stor=cal;
v=0.0;
cal.clear();
s=new MyPoint();
surfacePoint(u,v,1,s);
cal.push_back(s);
for (j=1; j<=NUMBER; j++)
{
v=(double)j/fNUMBER*n;
glBegin(GL_POLYGON);
glVertex3f(stor[j-1]->x,st
glVertex3f(stor[j]->x,stor
s=new MyPoint();
surfacePoint(u,v,1,s);
cal.push_back(s);
glVertex3f(cal[j]->x,cal[j
glVertex3f(cal[j-1]->x,cal
glEnd();
}
}
for (i=0;i<cal.size();i++) delete cal[i];
for (int k=0;k<stor.size();k++) delete stor[k];
}
void CBSplineView::surfacePoint
{
int i,j,k,l;
double s,t,temp;
i=floor(u*h);
j=floor(v*h);
s=(u-floor(u))*h;
t=(v-floor(v))*h;
temp=0.0;
for (k=0;k<=m_p;k++)
{
for (l=0;l<=m_q;l++)
{
temp=temp+B(k,m_p,s)*B(l,m
}
}
S->x=u;
S->y=v;
S->z=temp;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! i3 is out of range at a very special point. Other variables are OK.
How you want to evaluate above expression ? Do close it with proper parenthesis.
MAHESH