Skip to main content
GameDev.net gamedev.net
🔒 Locked

Access Violations in wdmaud.drv

Started by -Thork- Jun 4, 2002 at 3:28 PM 3 replies 3.1k views
Original Post
-Thork-
-Thork-
I''ve written a class that loads a wave file into memory, takes the necessary information from it to fill a WAVEFORMATEX structure and when a function is called, a waveOut device is opened and the file is played. The file plays fine, however, when the file is finished playing, I get an access violation. The code for playing the file is below:
  
bool CWaveFile::PlayWave()
{
	HWAVEOUT hWaveOut;
	WAVEHDR  whdr;

	if (!this->data) {
		return false;
	}

	if (waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfex, 0, 0, CALLBACK_NULL) != MMSYSERR_NOERROR) {
		return false;
	}

	VirtualLock(this->data, this->dwDataSize);

	memset(&whdr, 0, sizeof(WAVEHDR));
	whdr.lpData = this->data;
	whdr.dwBufferLength = this->dwDataSize;
	whdr.dwFlags = 0;
	whdr.dwLoops = 1;
	whdr.dwBytesRecorded = 0;
	whdr.dwUser = 0;

	if (waveOutPrepareHeader(hWaveOut, &whdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
		VirtualUnlock(this->data, this->dwDataSize);
		waveOutClose(hWaveOut);
		return false;
	}

	whdr.dwFlags |= WHDR_BEGINLOOP | WHDR_ENDLOOP;

	if (waveOutWrite(hWaveOut, &whdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
		VirtualUnlock(this->data, this->dwDataSize);
		waveOutClose(hWaveOut);
		return false;
	}

	return true;
}
  
I''ve tried everything. The code above has the callback function taken out to see if it was that, which it wasn''t. The access violation isn''t caused by the buffer being too small, and there are no problems that I can see in the WAVEFORMATEX structure or WAVEHDR structure. Any ideas? Your help will be greatly appreciated.
-Thork-
-Thork-
Note: I''m running XP, but that shouldn''t be the problem.

I''ve tried the same (well, simplified) code in VB aswell now and get the result. There is enough data in the buffer, but still the error occurs...
-Thork-
-Thork-
Ok, I''ve discovered it only occurs in Debug. When built for release it is fine...
Shannon Barber
Shannon Barber
I think the error still occurs, it just isn''t reported in the release build.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
-Thork-
-Thork-
I''ve got the answer now. It occurred to me this morning whilst watching TV, that I was deleting the WAVEHDR structure before waveOutWrite had finished using it. I hadn''t defined the WAVEHDR as part of the class, and it was being declared inside the function and so when the function returned (which happened before the wave had finished playing), the WAVEHDR structure was destroyed and so wdmaud.drv caused an access violation.

Ahh, sweet relief.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.