]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/sound_osx.cpp
re-enable drawing our own resize grip with GTK3, themes can (and do) disable the...
[wxWidgets.git] / src / osx / sound_osx.cpp
index 141552e29aa3f128c109a9320c6c77606edfb7c6..d671a5da22cdb7880fb84f0c36fb171dc454023a 100644 (file)
@@ -2,9 +2,9 @@
 // Name:        src/osx/sound_osx.cpp
 // Purpose:     wxSound class common osx code
 // Author:      Stefan Csomor
-// Modified by: 
+// Modified by:
 // Created:     2009-09-01
-// RCS-ID:      $Id: sound.cpp 61475 2009-07-20 16:47:54Z VZ $
+// RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -35,18 +35,20 @@ public:
     : m_sound(snd)
     {
     }
-    
+
     virtual ~wxSoundTimer()
     {
         Stop();
-        m_sound->DoStop();
+        if (m_sound)
+            m_sound->DoStop();
     }
-    
+
     void Notify()
     {
-        m_sound->SoundTask();
+        if (m_sound)
+            m_sound->SoundTask();
     }
-    
+
 protected:
     wxSoundData* m_sound;
 };
@@ -56,20 +58,22 @@ wxVector<wxSoundData*> s_soundsPlaying;
 wxSoundData::wxSoundData()
 {
     m_pTimer = NULL;
+    m_markedForDeletion = false;
 }
 
 wxSoundData::~wxSoundData()
 {
 }
 
+void wxSoundData::MarkForDeletion()
+{
+    m_markedForDeletion = true;
+}
+
 void wxSoundData::Stop()
 {
     DoStop();
-    if ( m_pTimer )
-    {
-        delete m_pTimer;
-        m_pTimer = NULL;
-    }
+    wxDELETE(m_pTimer);
 }
 
 //Time between timer calls
@@ -86,7 +90,7 @@ void wxSoundData::CreateAndStartTimer()
     m_pTimer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
 }
 
-wxSound::wxSound() 
+wxSound::wxSound()
 {
     Init();
 }
@@ -97,7 +101,7 @@ wxSound::wxSound(const wxString& sFileName, bool isResource)
     Create(sFileName, isResource);
 }
 
-wxSound::wxSound(int size, const wxByte* data)
+wxSound::wxSound(size_t size, const void* data)
 {
     Init();
     Create( size, data );
@@ -105,7 +109,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()
@@ -121,7 +142,7 @@ bool wxSound::DoPlay(unsigned flags) const
         if ( !m_data->Play(flags) )
             s_soundsPlaying.pop_back();
     }
-    
+
     return false;
 }
 
@@ -145,7 +166,7 @@ void wxSound::SoundStopped(const wxSoundData* data)
     for ( wxVector<wxSoundData*>::iterator s = s_soundsPlaying.begin();
          s != s_soundsPlaying.end(); ++s )
     {
-        if ( (*s) == data ) 
+        if ( (*s) == data )
         {
             s_soundsPlaying.erase(s);
             break;