From 5c95f7a249771f53cf1bfe3ff919bcae16b33f3b Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Sat, 6 Aug 2016 20:15:34 +0300 Subject: Fixed infinite loop caused by attempt to play blank MIDI-file --- src/adlmidi.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp index 7eca21c..8553cef 100644 --- a/src/adlmidi.cpp +++ b/src/adlmidi.cpp @@ -873,12 +873,19 @@ public: double Tick(double s, double granularity) { if(CurrentPosition.began) CurrentPosition.wait -= s; - while(CurrentPosition.wait <= granularity * 0.5) + int AntiFreezeCounter = 10000;//Limit 10000 loops to avoid freezing + while( (CurrentPosition.wait <= granularity * 0.5) && (AntiFreezeCounter>0) ) { //std::fprintf(stderr, "wait = %g...\n", CurrentPosition.wait); ProcessEvents(); + if(CurrentPosition.wait <= 0.0) + AntiFreezeCounter--; } + if(AntiFreezeCounter <= 0) + CurrentPosition.wait += 1.0;/* Add extra 1 second when over 10000 events + with zero delay are been detected */ + for(unsigned c = 0; c < opl.NumChannels; ++c) ch[c].AddAge(s * 1000); -- cgit v1.2.3