From 268d2ffe8b533890b408740db1a6a3730dfd8597 Mon Sep 17 00:00:00 2001 From: Tannin Date: Sun, 17 May 2015 14:03:01 +0200 Subject: - some code cleanup and modernization trying to fix "dr memory" reports (though they were almost certainly false positives) - there is now a 50ms timeout on logging messages - bugfix: leaked handles after directory searches --- src/logbuffer.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/logbuffer.cpp') diff --git a/src/logbuffer.cpp b/src/logbuffer.cpp index b58ef1de..0ddd927b 100644 --- a/src/logbuffer.cpp +++ b/src/logbuffer.cpp @@ -18,6 +18,7 @@ along with Mod Organizer. If not, see . */ #include "logbuffer.h" +#include #include #include #include @@ -127,7 +128,15 @@ char LogBuffer::msgTypeID(QtMsgType type) void LogBuffer::log(QtMsgType type, const QMessageLogContext &context, const QString &message) { - QMutexLocker guard(&s_Mutex); + // QMutexLocker doesn't support timeout... + if (!s_Mutex.tryLock(50)) { + fprintf(stderr, "failed to log: %s", qPrintable(message)); + return; + } + ON_BLOCK_EXIT([] () { + s_Mutex.unlock(); + }); + if (!s_Instance.isNull()) { s_Instance->logMessage(type, message); } @@ -192,9 +201,9 @@ QVariant LogBuffer::data(const QModelIndex &index, int role) const switch (role) { case Qt::DisplayRole: { if (index.column() == 0) { - return m_Messages.at(msgIndex).time; + return m_Messages[msgIndex].time; } else if (index.column() == 1) { - const QString &msg = m_Messages.at(msgIndex).message; + const QString &msg = m_Messages[msgIndex].message; if (msg.length() < 200) { return msg; } else { @@ -204,7 +213,7 @@ QVariant LogBuffer::data(const QModelIndex &index, int role) const } break; case Qt::DecorationRole: { if (index.column() == 1) { - switch (m_Messages.at(msgIndex).type) { + switch (m_Messages[msgIndex].type) { case QtDebugMsg: return QIcon(":/MO/gui/information"); case QtWarningMsg: return QIcon(":/MO/gui/warning"); case QtCriticalMsg: return QIcon(":/MO/gui/important"); @@ -214,7 +223,7 @@ QVariant LogBuffer::data(const QModelIndex &index, int role) const } break; case Qt::UserRole: { if (index.column() == 1) { - switch (m_Messages.at(msgIndex).type) { + switch (m_Messages[msgIndex].type) { case QtDebugMsg: return "D"; case QtWarningMsg: return "W"; case QtCriticalMsg: return "C"; -- cgit v1.3.1