diff --git a/hecl/include/hecl/Blender/BlenderConnection.hpp b/hecl/include/hecl/Blender/BlenderConnection.hpp index eb539707f..3b6414b91 100644 --- a/hecl/include/hecl/Blender/BlenderConnection.hpp +++ b/hecl/include/hecl/Blender/BlenderConnection.hpp @@ -51,6 +51,8 @@ public: }; private: std::atomic_bool m_lock = {false}; + bool m_pyStreamActive = false; + bool m_dataStreamActive = false; #if _WIN32 PROCESS_INFORMATION m_pinfo = {}; std::thread m_consoleThread; @@ -122,6 +124,7 @@ public: m_deleteOnError(deleteOnError), m_sbuf(*this, deleteOnError) { + m_parent->m_pyStreamActive = true; m_parent->_writeStr("PYBEGIN"); char readBuf[16]; m_parent->_readStr(readBuf, 16); @@ -143,6 +146,7 @@ public: m_parent->_readStr(readBuf, 16); if (strcmp(readBuf, "DONE")) BlenderLog.report(logvisor::Fatal, "unable to close PyOutStream with blender"); + m_parent->m_pyStreamActive = false; m_parent->m_lock = false; } } @@ -308,6 +312,7 @@ public: DataStream(BlenderConnection* parent) : m_parent(parent) { + m_parent->m_dataStreamActive = true; m_parent->_writeStr("DATABEGIN"); char readBuf[16]; m_parent->_readStr(readBuf, 16); @@ -328,6 +333,7 @@ public: m_parent->_readStr(readBuf, 16); if (strcmp(readBuf, "DONE")) BlenderLog.report(logvisor::Fatal, "unable to close DataStream with blender"); + m_parent->m_dataStreamActive = false; m_parent->m_lock = false; } } @@ -805,6 +811,7 @@ public: } BlenderToken() = default; + ~BlenderToken() { shutdown(); } BlenderToken(const BlenderToken&)=delete; BlenderToken& operator=(const BlenderToken&)=delete; BlenderToken(BlenderToken&&)=default; diff --git a/hecl/lib/Blender/BlenderConnection.cpp b/hecl/lib/Blender/BlenderConnection.cpp index 4bcc54121..11567a1cf 100644 --- a/hecl/lib/Blender/BlenderConnection.cpp +++ b/hecl/lib/Blender/BlenderConnection.cpp @@ -317,7 +317,8 @@ BlenderConnection::BlenderConnection(int verbosityLevel) CloseHandle(consoleErrWrite); CloseHandle(consoleOutWrite); - m_consoleThread = std::thread([&]() + m_consoleThreadRunning = true; + m_consoleThread = std::thread([=]() { CHAR lpBuffer[256]; DWORD nBytesRead; @@ -1550,8 +1551,24 @@ BlenderConnection::DataStream::getBoneMatrices(const std::string& name) void BlenderConnection::quitBlender() { - _writeStr("QUIT"); char lineBuf[256]; + if (m_lock) + { + if (m_pyStreamActive) + { + _writeStr("PYEND"); + _readStr(lineBuf, sizeof(lineBuf)); + m_pyStreamActive = false; + } + else if (m_dataStreamActive) + { + _writeStr("DATAEND"); + _readStr(lineBuf, sizeof(lineBuf)); + m_dataStreamActive = false; + } + m_lock = false; + } + _writeStr("QUIT"); _readStr(lineBuf, sizeof(lineBuf)); } diff --git a/hecl/lib/hecl.cpp b/hecl/lib/hecl.cpp index 5405bd1ec..a33892717 100644 --- a/hecl/lib/hecl.cpp +++ b/hecl/lib/hecl.cpp @@ -95,7 +95,7 @@ void SanitizePath(std::string& path) }); } -static const std::wstring WIllegals {L"<>?*\"|"}; +static const std::wstring WIllegals {L"<>?\"|"}; void SanitizePath(std::wstring& path) {