Skip to content

Commit

Permalink
Adding mutex lock to Logger
Browse files Browse the repository at this point in the history
ASSERT: "bytes <= bufferSize" in file tools\qringbuffer.cpp, line 74

This was happening when seeking multiple times very quickly in Player. QFile is not thread safe so I added a QMutexLocker to the Logger function.
  • Loading branch information
mike-odom committed Dec 16, 2018
1 parent f26fbf0 commit 330382c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 35,7 @@
#include <QtCore/QStandardPaths>
#endif
#include <QtDebug>
#include <QMutex>

#ifdef Q_OS_WINRT
#include <wrl.h>
Expand Down Expand Up @@ -98,8 99,13 @@ QtMsgHandler qInstallMessageHandler(QtMessageHandler h) {
return qInstallMsgHandler(MsgHandlerWrapper::handler);
}
#endif

QMutex loggerMutex;
void Logger(QtMsgType type, const QMessageLogContext &, const QString& qmsg)
{
// QFile is not thread-safe
QMutexLocker locker(&loggerMutex);

const QByteArray msgArray = qmsg.toUtf8();
const char* msg = msgArray.constData();
switch (type) {
Expand Down

0 comments on commit 330382c

Please sign in to comment.