To support playing async sounds on the stack on Mac, do not delete the wxSoundData when its wxSound object is destroyed if it's in the queue of sounds to be played. Instead, mark it to be deleted and delete it after it has played.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63023 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -30,6 +30,9 @@ public :
|
|||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
// can be called by a timer for repeated tasks during playback
|
// can be called by a timer for repeated tasks during playback
|
||||||
virtual void SoundTask();
|
virtual void SoundTask();
|
||||||
|
// mark this to be deleted
|
||||||
|
virtual void MarkForDeletion();
|
||||||
|
virtual bool IsMarkedForDeletion() const { return m_markedForDeletion; }
|
||||||
|
|
||||||
// does the true work of stopping and cleaning up
|
// does the true work of stopping and cleaning up
|
||||||
virtual void DoStop() = 0;
|
virtual void DoStop() = 0;
|
||||||
@@ -38,6 +41,7 @@ protected :
|
|||||||
|
|
||||||
unsigned int m_flags;
|
unsigned int m_flags;
|
||||||
wxSoundTimer* m_pTimer;
|
wxSoundTimer* m_pTimer;
|
||||||
|
bool m_markedForDeletion;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
class WXDLLIMPEXP_ADV wxSound : public wxSoundBase
|
class WXDLLIMPEXP_ADV wxSound : public wxSoundBase
|
||||||
|
@@ -100,6 +100,9 @@ void wxOSXSoundManagerSoundData::DoStop()
|
|||||||
m_pSndChannel = NULL;
|
m_pSndChannel = NULL;
|
||||||
wxSound::SoundStopped(this);
|
wxSound::SoundStopped(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IsMarkedForDeletion())
|
||||||
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxOSXSoundManagerSoundData::Play(unsigned flags)
|
bool wxOSXSoundManagerSoundData::Play(unsigned flags)
|
||||||
|
@@ -68,6 +68,9 @@ wxOSXAudioToolboxSoundData::CompletionCallback(SystemSoundID WXUNUSED(mySSID),
|
|||||||
wxOSXAudioToolboxSoundData* data = (wxOSXAudioToolboxSoundData*) soundRef;
|
wxOSXAudioToolboxSoundData* data = (wxOSXAudioToolboxSoundData*) soundRef;
|
||||||
|
|
||||||
data->SoundCompleted();
|
data->SoundCompleted();
|
||||||
|
|
||||||
|
if (data->IsMarkedForDeletion())
|
||||||
|
delete data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxOSXAudioToolboxSoundData::SoundCompleted()
|
void wxOSXAudioToolboxSoundData::SoundCompleted()
|
||||||
|
@@ -39,12 +39,14 @@ public:
|
|||||||
virtual ~wxSoundTimer()
|
virtual ~wxSoundTimer()
|
||||||
{
|
{
|
||||||
Stop();
|
Stop();
|
||||||
m_sound->DoStop();
|
if (m_sound)
|
||||||
|
m_sound->DoStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notify()
|
void Notify()
|
||||||
{
|
{
|
||||||
m_sound->SoundTask();
|
if (m_sound)
|
||||||
|
m_sound->SoundTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -56,12 +58,18 @@ wxVector<wxSoundData*> s_soundsPlaying;
|
|||||||
wxSoundData::wxSoundData()
|
wxSoundData::wxSoundData()
|
||||||
{
|
{
|
||||||
m_pTimer = NULL;
|
m_pTimer = NULL;
|
||||||
|
m_markedForDeletion = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSoundData::~wxSoundData()
|
wxSoundData::~wxSoundData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxSoundData::MarkForDeletion()
|
||||||
|
{
|
||||||
|
m_markedForDeletion = true;
|
||||||
|
}
|
||||||
|
|
||||||
void wxSoundData::Stop()
|
void wxSoundData::Stop()
|
||||||
{
|
{
|
||||||
DoStop();
|
DoStop();
|
||||||
@@ -105,7 +113,24 @@ wxSound::wxSound(int size, const wxByte* data)
|
|||||||
|
|
||||||
wxSound::~wxSound()
|
wxSound::~wxSound()
|
||||||
{
|
{
|
||||||
delete m_data;
|
// if the sound is in a playing state, just mark it to be deleted and
|
||||||
|
// delete it after it plays. Otherwise, async sounds created on the stack
|
||||||
|
// may never get the chance to play.
|
||||||
|
bool isPlaying = false;
|
||||||
|
for ( wxVector<wxSoundData*>::reverse_iterator s = s_soundsPlaying.rbegin();
|
||||||
|
s != s_soundsPlaying.rend(); ++s )
|
||||||
|
{
|
||||||
|
if (*s == m_data)
|
||||||
|
{
|
||||||
|
isPlaying = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPlaying)
|
||||||
|
m_data->MarkForDeletion();
|
||||||
|
else
|
||||||
|
delete m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxSound::Init()
|
void wxSound::Init()
|
||||||
|
Reference in New Issue
Block a user