git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63023
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
virtual void Stop();
// can be called by a timer for repeated tasks during playback
virtual void SoundTask();
virtual void Stop();
// can be called by a timer for repeated tasks during playback
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
virtual void DoStop() = 0;
// does the true work of stopping and cleaning up
virtual void DoStop() = 0;
unsigned int m_flags;
wxSoundTimer* m_pTimer;
unsigned int m_flags;
wxSoundTimer* m_pTimer;
+ bool m_markedForDeletion;
} ;
class WXDLLIMPEXP_ADV wxSound : public wxSoundBase
} ;
class WXDLLIMPEXP_ADV wxSound : public wxSoundBase
m_pSndChannel = NULL;
wxSound::SoundStopped(this);
}
m_pSndChannel = NULL;
wxSound::SoundStopped(this);
}
+
+ if (IsMarkedForDeletion())
+ delete this;
}
bool wxOSXSoundManagerSoundData::Play(unsigned flags)
}
bool wxOSXSoundManagerSoundData::Play(unsigned flags)
wxOSXAudioToolboxSoundData* data = (wxOSXAudioToolboxSoundData*) soundRef;
data->SoundCompleted();
wxOSXAudioToolboxSoundData* data = (wxOSXAudioToolboxSoundData*) soundRef;
data->SoundCompleted();
+
+ if (data->IsMarkedForDeletion())
+ delete data;
}
void wxOSXAudioToolboxSoundData::SoundCompleted()
}
void wxOSXAudioToolboxSoundData::SoundCompleted()
virtual ~wxSoundTimer()
{
Stop();
virtual ~wxSoundTimer()
{
Stop();
+ if (m_sound)
+ m_sound->DoStop();
+ if (m_sound)
+ m_sound->SoundTask();
wxSoundData::wxSoundData()
{
m_pTimer = NULL;
wxSoundData::wxSoundData()
{
m_pTimer = NULL;
+ m_markedForDeletion = false;
}
wxSoundData::~wxSoundData()
{
}
}
wxSoundData::~wxSoundData()
{
}
+void wxSoundData::MarkForDeletion()
+{
+ m_markedForDeletion = true;
+}
+
void wxSoundData::Stop()
{
DoStop();
void wxSoundData::Stop()
{
DoStop();
+ // 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;