diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index bd674c9fd7..c7796b4e02 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -11,6 +11,7 @@ #include #include + #include #include @@ -20,10 +21,12 @@ #include #include +#include #include #include #include #include +#include #include "utils/profilescombobox.hpp" #include "utils/textinputdialog.hpp" @@ -799,6 +802,7 @@ void Launcher::DataFilesPage::startNavMeshTool() ui.navMeshLogPlainTextEdit->clear(); ui.navMeshProgressBar->setValue(0); ui.navMeshProgressBar->setMaximum(1); + ui.navMeshProgressBar->resetFormat(); mNavMeshToolProgress = NavMeshToolProgress{}; @@ -825,6 +829,8 @@ void Launcher::DataFilesPage::readNavMeshToolStderr() void Launcher::DataFilesPage::updateNavMeshProgress(int minDataSize) { + if (!mNavMeshToolProgress.mEnabled) + return; QProcess& process = *mNavMeshToolInvoker->getProcess(); mNavMeshToolProgress.mMessagesData.append(process.readAllStandardError()); if (mNavMeshToolProgress.mMessagesData.size() < minDataSize) @@ -838,14 +844,23 @@ void Launcher::DataFilesPage::updateNavMeshProgress(int minDataSize) ui.navMeshProgressBar->maximum(), ui.navMeshProgressBar->value(), }; - while (true) + try + { + while (true) + { + NavMeshTool::Message message; + const std::byte* const nextPosition = NavMeshTool::deserialize(position, end, message); + if (nextPosition == position) + break; + position = nextPosition; + handle = std::visit(handle, NavMeshTool::decode(message)); + } + } + catch (const std::exception& e) { - NavMeshTool::Message message; - const std::byte* const nextPosition = NavMeshTool::deserialize(position, end, message); - if (nextPosition == position) - break; - position = nextPosition; - handle = std::visit(handle, NavMeshTool::decode(message)); + Log(Debug::Error) << "Failed to deserialize navmeshtool message: " << e.what(); + mNavMeshToolProgress.mEnabled = false; + ui.navMeshProgressBar->setFormat("Failed to update progress: " + QString(e.what())); } if (position != begin) mNavMeshToolProgress.mMessagesData = mNavMeshToolProgress.mMessagesData.mid(position - begin); @@ -874,7 +889,10 @@ void Launcher::DataFilesPage::navMeshToolFinished(int exitCode, QProcess::ExitSt ui.navMeshLogPlainTextEdit->appendPlainText( QString::fromUtf8(mNavMeshToolInvoker->getProcess()->readAllStandardOutput())); if (exitCode == 0 && exitStatus == QProcess::ExitStatus::NormalExit) + { ui.navMeshProgressBar->setValue(ui.navMeshProgressBar->maximum()); + ui.navMeshProgressBar->resetFormat(); + } ui.cancelNavMeshButton->setEnabled(false); ui.navMeshProgressBar->setEnabled(false); } diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 52b07da240..60082595c9 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -92,6 +92,7 @@ namespace Launcher private: struct NavMeshToolProgress { + bool mEnabled = true; QByteArray mLogData; QByteArray mMessagesData; std::map mWorldspaces; diff --git a/components/navmeshtool/protocol.cpp b/components/navmeshtool/protocol.cpp index 93c7e0cbf4..e3d52ade0c 100644 --- a/components/navmeshtool/protocol.cpp +++ b/components/navmeshtool/protocol.cpp @@ -5,6 +5,8 @@ #include #include +#include +#include #include #include @@ -12,6 +14,21 @@ namespace NavMeshTool { namespace { + std::string formatMagic(const char (&value)[std::size(messageMagic)]) + { + std::ostringstream stream; + for (const char v : value) + { + if (std::isprint(v) && !std::isspace(v)) + stream << '\'' << v << '\''; + else + stream << "0x" << std::hex << std::uppercase << std::setfill('0') << std::setw(2) + << static_cast(v); + stream << ' '; + } + return stream.str(); + } + template struct Format : Serialization::Format> { @@ -29,7 +46,7 @@ namespace NavMeshTool char magic[std::size(messageMagic)]; visitor(*this, magic); if (std::memcmp(magic, messageMagic, sizeof(magic)) != 0) - throw BadMessageMagic(); + throw std::runtime_error("Bad navmeshtool message magic: " + formatMagic(magic)); } visitor(*this, value.mType); visitor(*this, value.mSize); diff --git a/components/navmeshtool/protocol.hpp b/components/navmeshtool/protocol.hpp index f117f5001d..3ee8baa949 100644 --- a/components/navmeshtool/protocol.hpp +++ b/components/navmeshtool/protocol.hpp @@ -11,14 +11,6 @@ namespace NavMeshTool { inline constexpr char messageMagic[] = { 'n', 'v', 't', 'm' }; - struct BadMessageMagic : std::runtime_error - { - BadMessageMagic() - : std::runtime_error("Bad Message magic") - { - } - }; - enum class MessageType : std::uint64_t { ExpectedCells = 1,