DirectSound...sound plays, but prog crashes halfway thru sound

Started by
3 comments, last by Mattman 22 years, 3 months ago
Okay, so as the title mentioned, I'm using DirectSound. The sound starts to play, but the program crashes immediately after the sound starts to play, and the sound gets cut off. There's no error box or anything, the application just goes *POOF* and disappears. I'm making a class for the sounds, and here's my sound-playing function.

HRESULT cSoundEngine:layWaveFile(TCHAR* sFileName, DWORD dwPlaySettings, bool bLoop)
{
	HRESULT hr;
	
	if ( !FAILED( ValidateWaveFile( sFileName ) ) )
	{
		// Allow for alteration of pan, volume, and frequency.
		dwPlaySettings |= DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
		
		SoundNode* newSoundNode = NULL;
		CSound* tempSound = NULL;
		
		// Load the wave file into a DirectSound buffer
		if( FAILED( hr = SoundManager->Create( &tempSound, sFileName, dwPlaySettings, GUID_NULL ) ) )
		{
			// Not a critical failure, so just update the status
			DXTRACE_ERR_NOMSGBOX( TEXT("Create"), hr );
//			MessageBox( hWnd, "Could not create sound buffer.",
//								"The Realm of Ralnar", MB_OK | MB_ICONERROR );
			return S_FALSE; 
		}
		
		// Only if the sound buffer was created perfectly should we update the UI 
		// and play the sound
		DWORD dwLoop = bLoop ? DSBPLAY_LOOPING : 0L;
		
		if( FAILED( tempSound->Play( 0, dwLoop ) ) )
		{
//			MessageBox( hWnd, "Error playing sound.", "The Realm of Ralnar", MB_OK | MB_ICONERROR );
			return DXTRACE_ERR( TEXT("Play"), hr );
		}
		
		// Add the playing sound to the linked list of currently playing sounds.
		newSoundNode = new SoundNode;
		newSoundNode->entry = tempSound;
		newSoundNode->dwPlaySettings = dwPlaySettings;
		newSoundNode->next = NULL;
		tail->next = newSoundNode;
		tail = newSoundNode;
		
		return(S_OK);
	}
	else
		return(E_FAIL);
}
 
If anyone knows why my program starts to play and then crashes, please let me know. All help is appreciated! Mattman Nobis Productions Edited by - Mattman on January 15, 2002 4:04:47 PM
Advertisement
well, no time at the moment to check everything...
but one question: is this the first time you
use your own linked list implementation,
or have you tested it for several other tasks?
if not, try to use stl library, or try other
things with your list, and see if it crashes, too.

I''ve used linked lists in the past, and I''ve done everything just fine. I don''t think that''s the problem, but when I have a chance, I''ll look into it a bit more. So if anyone else has any other suggestions, I appreciate them!
should:
quote:
newSoundNode = new SoundNode;

be:
quote:
newSoundNode = new SoundNode();

?

is it bomb on the first sound played? If so, than at:
quote:
tail->next = newSoundNode;

might crash, as tail might not be initialized, so tail may point to any memory address. Try this:

MessageBox(NULL, "Wait", "Wait", MB_OK);

// Add the playing sound to the linked list of currently playing sounds.
newSoundNode = new SoundNode;
newSoundNode->entry = tempSound;
...

Don''t click OK on the message box and see if the sound completes. If so, it''s that section of code.


Jim Adams
Ahh! I think you''re right! I don''t have my tail initialized to anything. Thanks so much, I''ll try it out!

This topic is closed to new replies.

Advertisement