]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/sound_osx.cpp
setting correct 'default' for m_filterIndex, closes #11541
[wxWidgets.git] / src / osx / sound_osx.cpp
index 141552e29aa3f128c109a9320c6c77606edfb7c6..1155660e46ddb01ae0e634760927b6fb7f7ca83a 100644 (file)
@@ -39,12 +39,14 @@ public:
     virtual ~wxSoundTimer()
     {
         Stop();
-        m_sound->DoStop();
+        if (m_sound)
+            m_sound->DoStop();
     }
     
     void Notify()
     {
-        m_sound->SoundTask();
+        if (m_sound)
+            m_sound->SoundTask();
     }
     
 protected:
@@ -56,12 +58,18 @@ wxVector<wxSoundData*> s_soundsPlaying;
 wxSoundData::wxSoundData()
 {
     m_pTimer = NULL;
+    m_markedForDeletion = false;
 }
 
 wxSoundData::~wxSoundData()
 {
 }
 
+void wxSoundData::MarkForDeletion()
+{
+    m_markedForDeletion = true;
+}
+
 void wxSoundData::Stop()
 {
     DoStop();
@@ -105,7 +113,24 @@ wxSound::wxSound(int size, const wxByte* data)
 
 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()