Skip to content

Commit

Permalink
Cmd line: -m and -no-mb: fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcw committed Nov 3, 2019
1 parent 5792107 commit d92eca5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions source/Mockingboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,11 @@ void MB_InitializeForLoadingSnapshot() // GH#609
{
MB_Reset();
InitSoundcardType();

if (g_bDisableDirectSound || g_bDisableDirectSoundMockingboard)
return;

_ASSERT(MockingboardVoice.lpDSBvoice);
MockingboardVoice.lpDSBvoice->Stop(); // Reason: 'MB voice is playing' then loading a save-state where 'no MB present'
}

Expand Down Expand Up @@ -1701,6 +1706,9 @@ void MB_InitializeIO(LPBYTE pCxRomPeripheral, UINT uSlot4, UINT uSlot5)

MB_SetSoundcardType(g_Slot[4]);

if (g_bDisableDirectSound || g_bDisableDirectSoundMockingboard)
return;

// Sound buffer may have been stopped by MB_InitializeForLoadingSnapshot().
// NB. DSZeroVoiceBuffer() also zeros the sound buffer, so it's better than directly calling IDirectSoundBuffer::Play():
// - without zeroing, then the previous sound buffer can be heard for a fraction of a second
Expand Down
1 change: 1 addition & 0 deletions source/SoundCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ bool DSZeroVoiceBuffer(PVOICE Voice, char* pszDevName, DWORD dwBufferSize)
DWORD dwDSLockedBufferSize = 0; // Size of the locked DirectSound buffer
SHORT* pDSLockedBuffer;

_ASSERT(Voice->lpDSBvoice);
HRESULT hr = Voice->lpDSBvoice->Stop();
if(FAILED(hr))
{
Expand Down

0 comments on commit d92eca5

Please sign in to comment.