Re: waveINxxx "bad pointer" error in Debug version
- From: "Mitch Gallant" <jensigner@xxxxxxxxxxxxxxxx>
- Date: Tue, 10 Feb 2009 21:13:50 -0400
"Chris P." <msdn@xxxxxxxxxxxx> wrote in message
news:19xmn4dhp7t8i.c7dd9b295sst.dlg@xxxxxxxxxxxxx
On Tue, 10 Feb 2009 16:25:31 -0400, Mitch Gallant wrote:
Here is what happens when I put a breakpoint and debug the *release*
version:
checking both pwaveHdr1 and pWaveHdr2 ... both are valid with no errors
in
pointers and with a dwFlag for both set at 3 (as expected ... headers
have
been prepared and are ready).
I ran this several times and get the same result always.
Now putting a breakpoint at same location and debugging the *debug*
version
always causes
pWaveHdr1 to have invalid pointer and the dwFlag is set to 0
pWaveHdr2 is valid (as the two headers were in the release version),
This seems to indicate something with the debug rt library causing the
problem.
The two waveheaders are prepared in exactly the same way and the code is
pretty simple standard code (again based on Petzold) for initializing and
preparing the buffers once, receiving full buffers for MM_WIM_DATA and
releasing them again with waveInAddBuffer()
The pointer pwaveHdr1 is in your data section (or stack) so if the pointer
value has changed then you have heap/stack corruption. I have never seen
this issue, and I have used waveIn extensively over the years with both
debug and release builds.
Problem solved.
I went back to the beginning in the DEBUG version and noticed that shortly
after the buffer allocations:
pBuffer1 = malloc (INP_BUFFER_SIZE) ;
pBuffer2 = malloc (INP_BUFFER_SIZE) ;
pBuffer1 was being corrupted (bad pointer). (The problem wasn't actually
with pWaveHdr.)
The problem was caused by another unrelated function call which had an
incorrect parameter:
I tend to use the text-generic (and define UNICODE and _UNICODE) and "safe"
time function
to get a date/time string:
time(&t1);
err1 = _wctime_s(ctimsize, sizeof(ctimsize)/sizeof(TCHAR), &t1);
//correct version!
I noticed that right after _wctime_s was called, pBuffer1 became a bad
pointer.
_wctime_s needs a buffer of 26 characters. Originally I forgot the
/sizeof(TCHAR) to get the proper buffer size in TCHAR. I was originally
getting 52 characters since I had UNICODE defined which didn't match TCHAR
ctimsize[26]. This didn't cause an error and _wctime_s returned no error.
But it must have caused a buffer over-reading and corrupted pBuffer1.
Anyway that fixed the problem. Thanks for the help trying to fix this.
Since both the debug and RELEASE versions have UNICODE and _UNICODE defined,
I'm still not sure why pBuffer1 wasn't similarly corrupted. At any rate, the
bug was a user-code bug.
Cheers,
- Mitch
.
- Follow-Ups:
- Re: waveINxxx "bad pointer" error in Debug version
- From: Chris P.
- Re: waveINxxx "bad pointer" error in Debug version
- References:
- waveINxxx "bad pointer" error in Debug version
- From: Mitch Gallant
- Re: waveINxxx "bad pointer" error in Debug version
- From: Chris P.
- Re: waveINxxx "bad pointer" error in Debug version
- From: Mitch Gallant
- Re: waveINxxx "bad pointer" error in Debug version
- From: Chris P.
- waveINxxx "bad pointer" error in Debug version
- Prev by Date: Re: waveINxxx "bad pointer" error in Debug version
- Next by Date: WaveMon Sound-card counting utility
- Previous by thread: Re: waveINxxx "bad pointer" error in Debug version
- Next by thread: Re: waveINxxx "bad pointer" error in Debug version
- Index(es):
Relevant Pages
|
Loading