BlenderConnection stability improvements for Windows

This commit is contained in:
Jack Andersen 2016-12-25 12:15:31 -10:00
parent 0bf5499717
commit 77c3d1e184
3 changed files with 27 additions and 3 deletions

View File

@ -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;

View File

@ -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));
}

View File

@ -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)
{