Unhandled Exception Error

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 11
Reputation: teddybouch is an unknown quantity at this point 
Solved Threads: 0
teddybouch teddybouch is offline Offline
Newbie Poster

Unhandled Exception Error

 
0
  #1
Oct 17th, 2008
I am resurrecting old code from a few years ago, and I unfortunately have little documentation as to how it was compiled and what environment it was built in. At this point, I have successfully gotten it to build, but there are errors at execution, specifically an unhandled exception error on a memory access. The error text is:

Unhandled exception at 0x0002cb80 in Lab4_2008.exe: 0xC0000005: Access violation reading location 0x0002cb80.
It is always the same memory address that is the location, and when I break out of the program it takes me to the following function:

  1. UINT
  2. CHapticThread::GetClosestPossiblePeriod(UINT period)
  3. {
  4. TIMECAPS timecaps;
  5. MMRESULT mmRes;
  6.  
  7. mmRes = ::timeGetDevCaps( &timecaps, sizeof(TIMECAPS) );
  8. assert(mmRes == TIMERR_NOERROR);
  9.  
  10. if ( period < timecaps.wPeriodMin )
  11. return timecaps.wPeriodMin;
  12.  
  13. if ( period > timecaps.wPeriodMax )
  14. return timecaps.wPeriodMax;
  15.  
  16. return period;
  17. }

Specifically, it's the call to timeGetDevCaps that is where the error occurs. I don't pretend to know all the intricacies of how pointers work - I am a mechanical engineer who has picked up some programming. However, that's the only thing that I can think of because of the association with an address. Any suggestions?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: Unhandled Exception Error

 
0
  #2
Oct 17th, 2008
well, show us your timeGetDevCaps function for start
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Unhandled Exception Error

 
0
  #3
Oct 17th, 2008
I think it's just this.
http://msdn.microsoft.com/en-us/library/ms713416.aspx

But the execution address and the read address being the same seems kinda odd to me.

If that really is the case, then the code took a flying jump off a cliff (typically, following an uninitialised function pointer). The "stack" at that point is pretty much meaningless, so I wouldn't put too much store in that.

Putting a breakpoint at the call, then trying "step over" would give more concrete information as to whether this was the cause, or merely the last bit of salvageable stack from the disaster which follows.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 11
Reputation: teddybouch is an unknown quantity at this point 
Solved Threads: 0
teddybouch teddybouch is offline Offline
Newbie Poster

Re: Unhandled Exception Error

 
0
  #4
Oct 17th, 2008
Sorry, you lost me on the execution address and the read address being the same. The attempted read address is repeated twice, if that's what you are referring to, but that's what happened everywhere else I saw the error.

Salem is correct - the timeGetDevCaps function is a part of the winmm.lib file, which means that I can't see the code and don't know how the constructor initializes everything.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Unhandled Exception Error

 
0
  #5
Oct 17th, 2008
The same means this:
Unhandled exception at 0x0002cb80 in Lab4_2008.exe: 0xC0000005: Access violation reading location 0x0002cb80.

But did you do as I suggest, put a breakpoint on
mmRes = ::timeGetDevCaps( &timecaps, sizeof(TIMECAPS) );
then step over it?

It that works, then the problem is somewhere else.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 305
Reputation: stilllearning has a spectacular aura about stilllearning has a spectacular aura about 
Solved Threads: 43
stilllearning stilllearning is offline Offline
Posting Whiz

Re: Unhandled Exception Error

 
0
  #6
Oct 17th, 2008
Well I tried putting your stuff in a standalone program and it works without any difficulties.

It is possible that you have code elsewhere which is corrupting your stack, and the problem shows up when you call timeGetDevCaps. Have you considered running your code through a memory checking tool ?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Unhandled Exception Error

 
0
  #7
Oct 17th, 2008
> Well I tried putting your stuff in a standalone program and it works without any difficulties.
Yeah, tests like that pretty much nail the "it's a bug elsewhere" argument.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC