aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2021-01-07 00:12:40 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2021-01-07 00:12:40 +0800
commitb95c8edec5249b216b5d1ba8512ed5b653090b08 (patch)
tree55290b6d951b4183772b16160e72e7d0b3c0afc9
parent5e6e4615264214cf86cd74d63938c503fd36b74d (diff)
downloadQMidiPlayer-b95c8edec5249b216b5d1ba8512ed5b653090b08.tar.xz
Fix very random crashes when run with QtCreator and freezes on Windows.
Guys, don't code at 1am.
-rw-r--r--core/qmpmidiplay.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/core/qmpmidiplay.cpp b/core/qmpmidiplay.cpp
index 7e35b95..6a24024 100644
--- a/core/qmpmidiplay.cpp
+++ b/core/qmpmidiplay.cpp
@@ -245,9 +245,9 @@ void CMidiPlayer::playEvents()
if (ns_sleep + correction > 2.5e8)
{
high_resolution_clock::time_point t = high_resolution_clock::now();
- uint64_t tts = uint64_t(ns_sleep + correction);
+ int64_t tts = int64_t(ns_sleep + correction);
std::unique_lock<std::mutex> lock(intmtx);
- std::cv_status intr = intcv.wait_for(lock, std::chrono::nanoseconds(uint64_t(ns_sleep + correction - 5e7)));
+ std::cv_status intr = intcv.wait_for(lock, std::chrono::nanoseconds(int64_t(ns_sleep + correction - 1e8)));
if (intr == std::cv_status::no_timeout)
{
if (tcstop)
@@ -255,7 +255,7 @@ void CMidiPlayer::playEvents()
break;
}
}
- tts -= uint64_t((high_resolution_clock::now() - t).count());
+ tts -= int64_t((high_resolution_clock::now() - t).count());
if (tts > 0 && intr == std::cv_status::timeout && !tcstop && midiReaders)
{
#ifdef _WIN32
@@ -264,6 +264,10 @@ void CMidiPlayer::playEvents()
std::this_thread::sleep_for(std::chrono::nanoseconds(tts));
#endif
}
+ else if (tts < 0)
+ {
+ fputs("ur operating system (or toolchain) suck!!\n", stderr);
+ }
}
else
{
@@ -471,7 +475,6 @@ void CMidiPlayer::setTCeptr(uint32_t ep, uint32_t st)
if (ep == ecnt)
tcstop = true;
else tceptr = ep;
- this->interrupt();
for (int i = 0; i < 16; ++i)
{
qmpMidiOutDevice *dest = mididev[mappedoutput[i]].dev;
@@ -493,6 +496,7 @@ void CMidiPlayer::setTCeptr(uint32_t ep, uint32_t st)
ctsd = 1 << ((ccstamps[st][0][132] >> 16) & 0xFF);
cks = ccstamps[st][0][133];
}
+ this->interrupt();
}
double CMidiPlayer::getFtime()
{
@@ -565,6 +569,7 @@ void CMidiPlayer::setTCpaused(uint32_t ps)
void CMidiPlayer::interrupt()
{
+ std::lock_guard<std::mutex> lk(intmtx);
intcv.notify_one();
}
uint32_t CMidiPlayer::isFinished()