Learn how to a build a cloud-first strategyRegister Now


Access violation, cannot read memory xxxxxxx

Posted on 2006-04-03
Medium Priority
Last Modified: 2013-11-20
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();
      std::vector<MyPoint*> stor,cal;
      int i,j;
      double u,v;
      for (i=0;i<cal.size();i++) delete cal[i];
      for (j=0;j<=NUMBER; j++)
            s=new MyPoint();
      for (i=1; i<=NUMBER; i++)  
            for (int k=0;k<stor.size();k++) delete stor[k];
            s=new MyPoint();
            for (j=1; j<=NUMBER; j++)
                        s=new MyPoint();
      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;



      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)*points[(i+k)*(n*h+m_q)+j+l]->z; // WHEN AN ERROR OCCURS, THE PROGRAM STOPS AT THIS LINE.

Question by:applebibo
LVL 48

Accepted Solution

AlexFM earned 800 total points
ID: 16367814
I guess some index is out of range. Replace this line with number of lines by the following way:

int i1 = B(k,m_p,s);
int i2 = B(l,m_q,t);
int i3= (i+k)*(n*h+m_q)+j+l;   // this is index, possibly out of range
MyPoint* p1 = mypoints[i3];
temp = i1 * i2 ...;

This can give more information what happens. When exception occurs, enter debugger and see variable values.

LVL 22

Expert Comment

ID: 16367843
temp=temp+B(k,m_p,s)*B(l,m_q,t)*points[(i+k)*(n*h+m_q)+j+l]->z; <== whats values of m_p and m_q ? have you crosschecked them at run time ?

How you want to evaluate above expression ? Do close it with proper parenthesis.


Author Comment

ID: 16375285
Thanks! i3 is out of range at a very special point. Other variables are OK.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Integration Management Part 2
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question