Skip to content

Commit 0337c8b

Browse files
committed
Fixed a recursive call to the async::processMessages
1 parent ada22d1 commit 0337c8b

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

src/framework/audio/engine/internal/export/soundtrackwriter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ Ret SoundTrackWriter::generateAudioData()
148148

149149
sendStepProgress(PREPARE_STEP, inputBufferOffset, inputBufferMaxOffset);
150150

151-
const std::thread::id thisThId = std::this_thread::get_id();
152151
while (inputBufferOffset < inputBufferMaxOffset && !m_isAborted) {
153152
m_source->process(m_intermBuffer.data(), m_renderStep);
154153

@@ -163,7 +162,6 @@ Ret SoundTrackWriter::generateAudioData()
163162

164163
//! NOTE It is necessary for cancellation to work
165164
//! and for information about the audio signal to be transmitted.
166-
async::processMessages(thisThId);
167165
rpcChannel()->process();
168166
}
169167

src/framework/audio/engine/internal/synthesizers/fluidsynth/fluidsynth.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ using namespace muse::audio;
3737
using namespace muse::audio::synth;
3838
using namespace muse::mpe;
3939

40+
static constexpr bool FLUID_DEBUG = false;
41+
4042
static constexpr double FLUID_GLOBAL_VOLUME_GAIN = 4.8;
4143
static constexpr int DEFAULT_MIDI_VOLUME = 100;
4244
static constexpr msecs_t MIN_NOTE_LENGTH = 10;
@@ -90,7 +92,9 @@ Ret FluidSynth::init(const OutputSpec& spec)
9092
LOGI() << message;
9193
} break;
9294
case FLUID_DBG: {
93-
LOGD() << message;
95+
if (FLUID_DEBUG) {
96+
LOGD() << message;
97+
}
9498
} break;
9599
}
96100

src/framework/global/thirdparty/kors_async/async/async.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,16 @@ class Async
135135
{
136136
Call func;
137137
Func(const Call& f = nullptr)
138-
: func(f) {}
138+
: func(f)
139+
{
140+
assert(func && "callback is nullptr");
141+
}
139142

140143
void call(const void*) override
141144
{
142-
func();
145+
if (func) {
146+
func();
147+
}
143148
}
144149
};
145150

src/framework/global/thirdparty/kors_async/async/internal/rpcqueue.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class RpcPort
7474
std::vector<T> m_buffer;
7575
std::queue<T> m_pending;
7676
std::function<void(const T&)> m_handler;
77+
bool m_isProcessing = false;
7778

7879
public:
7980

@@ -94,6 +95,19 @@ class RpcPort
9495

9596
assert(m_connPort);
9697

98+
assert(!m_isProcessing && "Recursive processing of messages is not allowed");
99+
100+
if (m_isProcessing) {
101+
return;
102+
}
103+
104+
struct Guard {
105+
bool& flag;
106+
Guard(bool& flag)
107+
: flag(flag) { flag = true; }
108+
~Guard() { flag = false; }
109+
} guard { m_isProcessing };
110+
97111
// receive messages
98112
m_buffer.clear();
99113
bool ok = m_connPort->m_queue.tryPopAll(m_buffer);

src/project/qml/MuseScore/Project/internal/Export/exportdialogmodel.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <algorithm>
2525

2626
#include <QItemSelectionModel>
27+
#include <QTimer>
2728

2829
#include "async/async.h"
2930
#include "translation.h"
@@ -425,7 +426,11 @@ bool ExportDialogModel::exportScores()
425426
shouldDestinationFolderBeOpenedOnExport() };
426427

427428
std::shared_ptr<IExportProjectScenario> scenario = exportProjectScenario();
428-
async::Async::call(nullptr, [scenario, params]() {
429+
430+
//! NOTE We can't use Async here
431+
// because the async::processMessages is called deep within the functions,
432+
// and this can't be done in Async's callback.
433+
QTimer::singleShot(0, [scenario, params]() {
429434
scenario->exportScores(params.notations, params.exportPath, params.selectedUnitType, params.openFolderOnExport);
430435
});
431436

0 commit comments

Comments
 (0)