Solved

Access Violation Quandry

Posted on 1998-06-06
10
155 Views
Last Modified: 2013-11-19
null
0
Comment
Question by:oceanic
  • 5
  • 3
  • 2
10 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 1316128
Function calls don't randomly happen. You've either got a bogus version of your DLL lying around someplace (perhaps locked in memory by an instance of your app that crashed and wasn't terminated correctly), or you're linking with the wrong import LIB files, or your code is really explicitly or explicitly calling the function.

Those are the only possible causes; you have to figure out which one is happening and remedy it. If you haven't found it yet, you're not looking hard enough, or not looking at the right places.

B ekiM

0
 

Author Comment

by:oceanic
ID: 1316129
You don't suppose I could find a problem beyond your reach?  My first instinct was to be unprofessional and simply say, "bite me".  I will refrain from making it official, and simply point out that after I read your unhelpful (and arrogantly rude) reply, I went immediately and rebooted my system (to make sure and clear the "bogus" dll that somehow survived other reboots in between all those days I have spent on this problem).  I then proceeded to the "Find->Files or Folders..." option on the Start menu and located each and every last copy of *all* of my DLLs and deleted them.  I then performed another search for *all* of my .LIB files and deleted them.  Again, anywhere they existed on my entire system, I deleted them.  I then removed the blindfold from my eyes and turned my chair around 180 degrees to face my monitor.  I also plugged in and turned on my monitor, to make sure that the code which I had typed in over the last several weeks was something I was familiar with; I didn't find any "explicit calls to functions" (in your words) where I hadn't intended them.  I then walked out in the backyard and looked around *real hard* to see if maybe my code problem was under any rocks (because I hadn't looked under rocks, just in trees so far).  Didn't find it.  Gee, I was shocked.

Read my original message again.  I already answered every one of your "suggestions".

My code still got the same Access Violation in the same exact place after having done another full rebuild (and of course after all those steps I listed for you above).  But maybe I haven't looked hard enough...

Oh, I'm open to input and help, but in my opinion your reply was neither.  For other readers, let me state for the record that it may be something I have overlooked, but the problem has forced me to spend many hours "weeding out" the simpler possible (and probable) causes.  I am seeking an answer from someone who has experienced the same phenomenon.  Maybe it's a strange bug in MFC, as there have been plenty of them over the years.  If anyone else has any ideas, please let me know.  I figured from the beginning that I would need to provide more detail or examples, as it is not a simple problem.  If it was, I wouldn't have posted my first request.

And advice to the "experts" (especially any self-proclaimed ones)...don't reply to a question as if someone is an idiot.  Maybe they've spent days and weeks on the issue, losing sleep over it and maybe they happen to know what they're doing in general.  Geez, maybe they do...

If I heed no other advice, I should at least stop ranting now.  I may have started a fire that shouldn't be burning here, and for that I apologize, but I know I am not the first to ask an honest question and get something worse than a wrong answer.
Oceanic
0
 
LVL 11

Expert Comment

by:alexo
ID: 1316130
You say you don't call tis function at all?
OK, consider the following random thoughts:

Maybe you make indirect function calls (via a function pointer) and the pointer got garbled somehow and now points to the wrong address?

Maybe you overflow an object's bounds, overwriting it's vtable in the process?

You have the source to MFC.  Why don't you put a breakpoint in CView::OnCmdMsg() near line 171 and see what's going on?
0
 
LVL 11

Accepted Solution

by:
alexo earned 250 total points
ID: 1316131
OK, got it.

The line that fails is probably (MSVC 4.2: VIEWCORE.CPP, line 171):
    bHandled = m_pDocument->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);

The m_pDocument member pointer got trashed somewhere and calling a function through it gives an address that happens to be the address of your function.  (Another option is that the "this" pointer of the CView is invalid at the time of the call, which complicates matters).

Anyway, seems that your problem lies earlier in the call chain or even before, in another method altogether.  Try watching m_pDocument while single stepping.
0
 

Author Comment

by:oceanic
ID: 1316132
alexo,

Thanks for the reply.  I am going to give the things you suggest a try.  The only one I can mark off the list right away is the "pointer to function".  I am not currently using any in my code at the moment.  As for the rest of your ideas, I will try to post my findings when I get a chance to work with the code again (in between work hours this week).

I noticed last night that my tree ctrl class correctly inserts an item into the ctrl (without the access violation occurring) when I don't pass a CDatabase pointer to the overloaded constructor.  However, when I revert the code to how I want it to work, passing a CDatabase pointer, I get the weird access violation.  The CDatabase object itself is a public member of my CDocument.  I am doing a TreeCtrl->Function(&(m_pDoc->m_Database)) type of call.  The m_pDoc is initialized in my view:OnCreate function.  I don't know if this sheds any more light on the issue.

Also, I had many times stopped at breakpoints in the MFC source, and the access violation seems to happen when the window is being brought to the front of the z-order (which it then jumps to the same exact function in my database dll).  I didn't pursue this any further because it seems a symptom rather than the cause, but I will try and get more specifics.

Thanks again,
Oceanic
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:oceanic
ID: 1316133
alexo,
Correction to my response...the tree ctrl doesn't have an "overloaded constructor" as I mention.  (I typed the reply before I was fully awake.)  The tree ctrl has an overloaded *function* I am calling to populate it.  I am still using the GetTreeCtrl() call to get ahold of the tree ctrl.

Oceanic
0
 
LVL 11

Expert Comment

by:alexo
ID: 1316134
1. I was talking about the m_pDocument member of the CVeiw class (or one of it's descendants).

2. MFC uses virtual functions (which are really glorified pointers to functions) all over the place.  One overrun and you get the symptoms you mention.
0
 

Author Comment

by:oceanic
ID: 1316135
Yes...a "public" apology to mikeblas for my earlier response (June 6, 1998).  mikeblas has helped me -- and others no doubt -- before and I would like to acknowledge (in hindsight) that I responded way too defensively and probably misinterpreted his reply.  I had spent many hours pulling my hair out over the related issue to no avail and was, I suppose, a bomb with a short fuse.

mikeblas, if you will accept my professional and sincere apology, I would appreciate it.

oceanic
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1316136
I'm not sure: can you possibly see it from the "self-proclaimed expert's" side?  (Maybe the 10 months you've waited has provided you with some clarity.)

We have to walk the thinnest line. The information in your blitzkreig reply really wasn't in your original question: you never mentioned rebooting, or working for days, or deleting extra DLL copies, for example.

You mentioned that you did find in files; sure--but how am I to know you've done it correctly? I don't know you, or where you work, or what you know or don't know. How many times do you think I've answered questions from people who say they can't find the implementation of a particular MFC function because they don't know (or think to) search *.INL files? It's not outside of the realm of possibilities!

And so, I made a response that seemed appropriate. You didn't tell me what you'd done to solve the problem, and some of what you told me was (in my eyes) suspect. I had to start from square one.

When you answer questions like this, in whatever forum you answer them, you run the risk of insulting the questioner by asking questions that are too advanced, as well. I've been flamed many times by people who thought I was just out to embarrass them by suggesting they do things that they "obviously didn't understand".

Welp, how am I to know? In this case, you didn't tell me. So, I had to go with an assumption.  My other alternative is to ask you what you've done so far--and that's frequently interpreted as rude, too.

Would you do the same thing to your auto mechanic?

"It stalls."

"When?"

"Bit me!  Obviously, it stalls when it's _running_!"

Welp, that doesn't give the mechanic the information he needs to know to formulate a diagnosis. Is the mechanic a pit chief talking to a seasoned NASCAR driver, or is it the Honda mechanic trying to help someone who's never touched a wrench?

I made the response I did because your question made the problem sound as if you were suffering from a random, unobservable event beyond your control. It turns out, you're not; and I pointed that out. Seperating a frustrated, emotional reaction (like yours) from the real facts is tremendously important in scientific fields, like this one.

I've been flamed like this before. Sometimes worse, sometimes not as bad. (Search for "blaszczak near prick" on DejaNews, for instance.) Somehow, I manage to find the strength to continue helping people, usually by reminding myself that the flamer doesn't know what life looks like from the tops of my shoes.

Of course, it's never very long before someone again proves my tenacity to be foolish, like someone who insists on cooking when they're tired of the heat in the kitchen.
 
.B ekiM

0
 

Author Comment

by:oceanic
ID: 1316137
Again...sorry for the misunderstanding (and perhaps the grief).  The 10 months was simply the amount of time I stayed off of experts-exchange and yes, it did give me a better look at how I had way over-reacted.  I can understand your desire to clarify your approach to my original question, but whatever the case I wanted to sincerely apologize.

Honestly, I still didn't figure what was going on with the code because I didn't know any other places to look or things to try.  I got to the end of my endurance with it and decided to start the project over after some redesign.  By the time I get it developed, it'll be running on VC++ 8.5 or something...
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 98
has77  challenge 9 68
modThree challenge 4 64
EvenOdd challenge 10 83
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now