Fix deadlock in sampleplayer which caused problems in windows build.
authorDaniel Giritzer <giri@nwrk.biz>
Sat, 29 Dec 2018 14:55:45 +0000 (15:55 +0100)
committerDaniel Giritzer <giri@nwrk.biz>
Sat, 29 Dec 2018 14:55:45 +0000 (15:55 +0100)
src/SamplePlayer.cxx

index 5cbcc5d..ce5426d 100644 (file)
@@ -80,18 +80,17 @@ void SamplePlayer::thread_play(SamplePlayer* me, int driverID) {
     buffer = (short*)calloc(me->c_Buffer, sizeof(short));
     if (audioDevice != nullptr)
     {
-        while (1) {
-            int read = sf_read_short(me->m_SNDFile, buffer, me->c_Buffer);
-
+        int read = 0;
+        do {
+            read = sf_read_short(me->m_SNDFile, buffer, me->c_Buffer);
             if (ao_play(audioDevice, (char *) buffer, (uint_32) (read * sizeof(short))) == 0)
                 break;
 
-            if (me->m_Stop) {
+            if (me->m_Stop)
                 break;
-            }
-        }
+
+        } while(read > 0);
     }
-    delete []buffer;
     ao_close(audioDevice);
     me->setFinished(true);
 }