Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3303754
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:59:24+00:00 2026-05-17T20:59:24+00:00

C++. Its may be more question of debugging in Visual Studio and working with

  • 0

C++. Its may be more question of debugging in Visual Studio and working with memory.

I have a program that analyzes list of files, and path to current file is a concatenation of to strings: CString object named ‘folder’ and filename itself(CString too).

But after 144’th iteration(im sure the number is unimportant), folder suddenly turns into a BadPtr and application crashes with Access Violation. To check, i’ve created a CFileFind object with the same directory and instead of concatenating with folder i concatenate with finder.GetRoot(). Same story, 144th iteration and crash.

The question is, how can i protect the memory of this variable(its ok before 144th iteration) or trace the function which actually writes on that location or whatever else to debug this problem. During the cycle, folder variable is not changed at all. Actually its within the private section of some class and all functions appearing in the cycle have no acces to this private section.

Code goes like this(there can be some typos cuz i cut some unimportant things out of it):

typedef map<CString, list< CRect > > metadata;
...
metadata::iterator it=mt.begin();
list< CRect >::iterator it_l;
float i=0;

while(it!=mt.end()){
        if(cur.Load(folder+"\\"+(*it).first+".jpg")){
            it_l=(*it).second.begin();
            i+=1.0;
            while(it_l!=(*it).second.end()){
                cur.buildVector(*it_l);
                cur.printVector(mf,',');
                mf<<",1"<<"\n";
                it_l++;
            }
        }
        it++;
    }

buildVector collects features in CRect object of current image, cur.Load loads the image itsef, printVector prints vector to ofstream named mf.
i counts iterations.

UPDATE: I examined my code, commented all the lines but cur.Load(…) and still had crash but on 584th iteration. Looks like its overwriting memory problem. I looked through all the functions in Load:

    bool Image::Load(CString& path){
     if(!src.IsNull()){ 
        src.Destroy();
     }
     src.Load(path);    
     width=src.GetWidth();
     height=src.GetHeight();
     fillBrightnessMatrix();
     fillGradientMatrices();
     return true;
    }

and discovered that commenting fillBrightnessMatrix() makes iterations go through the end of the list without any errors. This function is the only one that works with memory, and here goes its code:

 void Image::fillBrightnessMatrix(){
    const int nPitch = src.GetPitch();

    const unsigned int nWidth = src.GetWidth();
    const unsigned int nHeight = src.GetHeight();
    BYTE * pxPixel = reinterpret_cast<BYTE*>(src.GetBits());


    for(int nY = 0; nY < nHeight; ++nY)
    { 
        for(int nX = 0; nX < nWidth; ++nX)
        {
            pxPixel += 3;
            bright[nX][nY]=((*pxPixel+*(pxPixel+1)+*(pxPixel+2))/3.0)/255.0;
        };

        if(nPitch >= 0)
            pxPixel += nPitch - (nWidth*3);
        else
            pxPixel -= ((nWidth*3) + (nPitch*(-1)));
    };
}

bright is allocated in constructor, its double[500][500]. Actually, i dont see any memory leaks in this code, what am i doing wrong?

Now debugger points to this line:

bright[nX][nY]=((*pxPixel+*(pxPixel+1)+*(pxPixel+2))/3.0)/255.0;

saying pxPixel is a BadPtr >.< damn i dont understand a thing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:59:25+00:00Added an answer on May 17, 2026 at 8:59 pm

    I haven’t looked at your code, but this smells like someone writing over the bounds of their data. To catch something like this:

    • Let your loop run up to the 143rd iteration. (Use a conditional breakpoint to break at the 143rd time.) Examine your folder to make sure it really is still Ok.
    • Set a data breakpoint on the address of its data. (I don’t know CString, so I can’t help you there.)
    • Single-step through the code.
    • When the data breakpoint hits, look at the stack to find out what’s happening.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

its out of question that a dao will not hold any state. however, for
It's been a while since I've programmed a GUI program, so this may end
Sometimes it's difficult to describe some of the things that us programmers may think
I know this may be a noob question, but it's bugging the heck out
I have a script that appends some rows to a table. One of the
Its possible I am just really really thick. However, looking over the SDK for
Its a simple config app with 4 checkboxes and 5 textboxes, and all values
Its a .vbproj and looks like this <Project DefaultTargets=Build xmlns=http://schemas.microsoft.com/developer/msbuild/2003> <PropertyGroup> <ProjectGuid>15a7ee82-9020-4fda-a7fb-85a61664692d</ProjectGuid> all i
If its dead, is there a successor? For those who didn't know: The Network
In its enthusiasm to stemm tokens into lexemes , PostgreSQL Full Text Search engine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.