mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 20:45:34 +00:00
Stop updating navmeshtool progress on first bad message
This commit is contained in:
parent
37152b4917
commit
f23866be90
4 changed files with 43 additions and 13 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <apps/launcher/utils/cellnameloader.hpp>
|
#include <apps/launcher/utils/cellnameloader.hpp>
|
||||||
|
|
||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
|
|
||||||
#include <components/contentselector/model/esmfile.hpp>
|
#include <components/contentselector/model/esmfile.hpp>
|
||||||
|
@ -22,6 +23,7 @@
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
#include <components/bsa/compressedbsafile.hpp>
|
#include <components/bsa/compressedbsafile.hpp>
|
||||||
#include <components/navmeshtool/protocol.hpp>
|
#include <components/navmeshtool/protocol.hpp>
|
||||||
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/vfs/bsaarchive.hpp>
|
#include <components/vfs/bsaarchive.hpp>
|
||||||
|
|
||||||
#include "utils/textinputdialog.hpp"
|
#include "utils/textinputdialog.hpp"
|
||||||
|
@ -787,6 +789,7 @@ void Launcher::DataFilesPage::startNavMeshTool()
|
||||||
ui.navMeshLogPlainTextEdit->clear();
|
ui.navMeshLogPlainTextEdit->clear();
|
||||||
ui.navMeshProgressBar->setValue(0);
|
ui.navMeshProgressBar->setValue(0);
|
||||||
ui.navMeshProgressBar->setMaximum(1);
|
ui.navMeshProgressBar->setMaximum(1);
|
||||||
|
ui.navMeshProgressBar->resetFormat();
|
||||||
|
|
||||||
mNavMeshToolProgress = NavMeshToolProgress {};
|
mNavMeshToolProgress = NavMeshToolProgress {};
|
||||||
|
|
||||||
|
@ -813,6 +816,8 @@ void Launcher::DataFilesPage::readNavMeshToolStderr()
|
||||||
|
|
||||||
void Launcher::DataFilesPage::updateNavMeshProgress(int minDataSize)
|
void Launcher::DataFilesPage::updateNavMeshProgress(int minDataSize)
|
||||||
{
|
{
|
||||||
|
if (!mNavMeshToolProgress.mEnabled)
|
||||||
|
return;
|
||||||
QProcess& process = *mNavMeshToolInvoker->getProcess();
|
QProcess& process = *mNavMeshToolInvoker->getProcess();
|
||||||
mNavMeshToolProgress.mMessagesData.append(process.readAllStandardError());
|
mNavMeshToolProgress.mMessagesData.append(process.readAllStandardError());
|
||||||
if (mNavMeshToolProgress.mMessagesData.size() < minDataSize)
|
if (mNavMeshToolProgress.mMessagesData.size() < minDataSize)
|
||||||
|
@ -826,14 +831,23 @@ void Launcher::DataFilesPage::updateNavMeshProgress(int minDataSize)
|
||||||
ui.navMeshProgressBar->maximum(),
|
ui.navMeshProgressBar->maximum(),
|
||||||
ui.navMeshProgressBar->value(),
|
ui.navMeshProgressBar->value(),
|
||||||
};
|
};
|
||||||
while (true)
|
try
|
||||||
{
|
{
|
||||||
NavMeshTool::Message message;
|
while (true)
|
||||||
const std::byte* const nextPosition = NavMeshTool::deserialize(position, end, message);
|
{
|
||||||
if (nextPosition == position)
|
NavMeshTool::Message message;
|
||||||
break;
|
const std::byte* const nextPosition = NavMeshTool::deserialize(position, end, message);
|
||||||
position = nextPosition;
|
if (nextPosition == position)
|
||||||
handle = std::visit(handle, NavMeshTool::decode(message));
|
break;
|
||||||
|
position = nextPosition;
|
||||||
|
handle = std::visit(handle, NavMeshTool::decode(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
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)
|
if (position != begin)
|
||||||
mNavMeshToolProgress.mMessagesData = mNavMeshToolProgress.mMessagesData.mid(position - begin);
|
mNavMeshToolProgress.mMessagesData = mNavMeshToolProgress.mMessagesData.mid(position - begin);
|
||||||
|
@ -861,7 +875,10 @@ void Launcher::DataFilesPage::navMeshToolFinished(int exitCode, QProcess::ExitSt
|
||||||
updateNavMeshProgress(0);
|
updateNavMeshProgress(0);
|
||||||
ui.navMeshLogPlainTextEdit->appendPlainText(QString::fromUtf8(mNavMeshToolInvoker->getProcess()->readAllStandardOutput()));
|
ui.navMeshLogPlainTextEdit->appendPlainText(QString::fromUtf8(mNavMeshToolInvoker->getProcess()->readAllStandardOutput()));
|
||||||
if (exitCode == 0 && exitStatus == QProcess::ExitStatus::NormalExit)
|
if (exitCode == 0 && exitStatus == QProcess::ExitStatus::NormalExit)
|
||||||
|
{
|
||||||
ui.navMeshProgressBar->setValue(ui.navMeshProgressBar->maximum());
|
ui.navMeshProgressBar->setValue(ui.navMeshProgressBar->maximum());
|
||||||
|
ui.navMeshProgressBar->resetFormat();
|
||||||
|
}
|
||||||
ui.cancelNavMeshButton->setEnabled(false);
|
ui.cancelNavMeshButton->setEnabled(false);
|
||||||
ui.navMeshProgressBar->setEnabled(false);
|
ui.navMeshProgressBar->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,7 @@ namespace Launcher
|
||||||
private:
|
private:
|
||||||
struct NavMeshToolProgress
|
struct NavMeshToolProgress
|
||||||
{
|
{
|
||||||
|
bool mEnabled = true;
|
||||||
QByteArray mLogData;
|
QByteArray mLogData;
|
||||||
QByteArray mMessagesData;
|
QByteArray mMessagesData;
|
||||||
std::map<std::uint64_t, std::string> mWorldspaces;
|
std::map<std::uint64_t, std::string> mWorldspaces;
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <components/serialization/binarywriter.hpp>
|
#include <components/serialization/binarywriter.hpp>
|
||||||
#include <components/serialization/binaryreader.hpp>
|
#include <components/serialization/binaryreader.hpp>
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -12,6 +14,21 @@ namespace NavMeshTool
|
||||||
{
|
{
|
||||||
namespace
|
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<int>(v);
|
||||||
|
stream << ' ';
|
||||||
|
}
|
||||||
|
return stream.str();
|
||||||
|
}
|
||||||
|
|
||||||
template <Serialization::Mode mode>
|
template <Serialization::Mode mode>
|
||||||
struct Format : Serialization::Format<mode, Format<mode>>
|
struct Format : Serialization::Format<mode, Format<mode>>
|
||||||
{
|
{
|
||||||
|
@ -29,7 +46,7 @@ namespace NavMeshTool
|
||||||
char magic[std::size(messageMagic)];
|
char magic[std::size(messageMagic)];
|
||||||
visitor(*this, magic);
|
visitor(*this, magic);
|
||||||
if (std::memcmp(magic, messageMagic, sizeof(magic)) != 0)
|
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.mType);
|
||||||
visitor(*this, value.mSize);
|
visitor(*this, value.mSize);
|
||||||
|
|
|
@ -11,11 +11,6 @@ namespace NavMeshTool
|
||||||
{
|
{
|
||||||
inline constexpr char messageMagic[] = {'n', 'v', 't', 'm'};
|
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
|
enum class MessageType : std::uint64_t
|
||||||
{
|
{
|
||||||
ExpectedCells = 1,
|
ExpectedCells = 1,
|
||||||
|
|
Loading…
Reference in a new issue