Blender verbose crash fix for windows

This commit is contained in:
Jack Andersen 2016-09-11 11:16:16 -10:00
parent 127343c6d1
commit 4bffe7bc8b
4 changed files with 73 additions and 12 deletions

View File

@ -171,6 +171,9 @@ void BlenderConnection::_closePipe()
#ifdef _WIN32
CloseHandle(m_pinfo.hProcess);
CloseHandle(m_pinfo.hThread);
m_consoleThreadRunning = false;
if (m_consoleThread.joinable())
m_consoleThread.join();
#endif
}
@ -241,6 +244,26 @@ BlenderConnection::BlenderConnection(int verbosityLevel)
SetHandleInformation(writehandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
HANDLE readhandle = HANDLE(_get_osfhandle(m_readpipe[1]));
SetHandleInformation(readhandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
SECURITY_ATTRIBUTES sattrs = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
HANDLE consoleOutReadTmp, consoleOutWrite, consoleErrWrite, consoleOutRead;
if (!CreatePipe(&consoleOutReadTmp, &consoleOutWrite, &sattrs, 0))
BlenderLog.report(logvisor::Fatal, "Error with CreatePipe");
if (!DuplicateHandle(GetCurrentProcess(), consoleOutWrite,
GetCurrentProcess(), &consoleErrWrite, 0,
TRUE,DUPLICATE_SAME_ACCESS))
BlenderLog.report(logvisor::Fatal, "Error with DuplicateHandle");
if (!DuplicateHandle(GetCurrentProcess(), consoleOutReadTmp,
GetCurrentProcess(),
&consoleOutRead, // Address of new handle.
0, FALSE, // Make it uninheritable.
DUPLICATE_SAME_ACCESS))
BlenderLog.report(logvisor::Fatal, "Error with DupliateHandle");
if (!CloseHandle(consoleOutReadTmp))
BlenderLog.report(logvisor::Fatal, "Error with CloseHandle");
#else
pipe(m_readpipe);
pipe(m_writepipe);
@ -272,16 +295,19 @@ BlenderConnection::BlenderConnection(int verbosityLevel)
verbosityLevel, blenderAddonPath.c_str());
STARTUPINFO sinfo = {sizeof(STARTUPINFO)};
HANDLE nulHandle = NULL;
HANDLE nulHandle = CreateFileW(L"nul", GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
&sattrs, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
sinfo.dwFlags = STARTF_USESTDHANDLES;
sinfo.hStdInput = nulHandle;
if (verbosityLevel == 0)
{
SECURITY_ATTRIBUTES sattrs = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
nulHandle = CreateFileW(L"nul", GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
&sattrs, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
sinfo.hStdInput = nulHandle;
sinfo.hStdError = nulHandle;
sinfo.hStdOutput = nulHandle;
sinfo.dwFlags = STARTF_USESTDHANDLES;
}
else
{
sinfo.hStdError = consoleErrWrite;
sinfo.hStdOutput = consoleOutWrite;
}
if (!CreateProcessW(blenderBin, cmdLine, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &sinfo, &m_pinfo))
@ -295,8 +321,36 @@ BlenderConnection::BlenderConnection(int verbosityLevel)
close(m_writepipe[0]);
close(m_readpipe[1]);
if (nulHandle)
CloseHandle(nulHandle);
CloseHandle(nulHandle);
CloseHandle(consoleErrWrite);
CloseHandle(consoleOutWrite);
m_consoleThread = std::thread([&]()
{
CHAR lpBuffer[256];
DWORD nBytesRead;
DWORD nCharsWritten;
while (m_consoleThreadRunning)
{
if (!ReadFile(consoleOutRead, lpBuffer, sizeof(lpBuffer),
&nBytesRead, NULL) || !nBytesRead)
{
if (GetLastError() == ERROR_BROKEN_PIPE)
break; // pipe done - normal exit path.
else
BlenderLog.report(logvisor::Fatal, "Error with ReadFile"); // Something bad happened.
}
// Display the character read on the screen.
auto lk = logvisor::LockLog();
if (!WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), lpBuffer,
nBytesRead, &nCharsWritten, NULL))
BlenderLog.report(logvisor::Fatal, "Error with WriteConsole");
}
CloseHandle(consoleOutRead);
});
#else
pid_t pid = fork();
@ -355,7 +409,7 @@ BlenderConnection::BlenderConnection(int verbosityLevel)
m_blenderProc = pid;
#endif
/* Stash error path an unlink existing file */
/* Stash error path and unlink existing file */
m_errPath = hecl::SystemString(TMPDIR) + hecl::SysFormat(_S("/hecl_%016llX.derp"), (unsigned long long)m_blenderProc);
hecl::Unlink(m_errPath.c_str());
@ -1230,7 +1284,7 @@ std::vector<BlenderConnection::DataStream::Light> BlenderConnection::DataStream:
std::vector<BlenderConnection::DataStream::Light> ret;
ret.reserve(lightCount);
for (int i=0 ; i<lightCount ; ++i)
for (uint32_t i=0 ; i<lightCount ; ++i)
ret.emplace_back(*m_parent);
return ret;

View File

@ -53,6 +53,8 @@ private:
#if _WIN32
HANDLE m_blenderProc = 0;
PROCESS_INFORMATION m_pinfo = {};
std::thread m_consoleThread;
bool m_consoleThreadRunning = true;
#else
pid_t m_blenderProc = 0;
#endif
@ -75,6 +77,11 @@ public:
BlenderConnection(int verbosityLevel=1);
~BlenderConnection();
BlenderConnection(const BlenderConnection&)=delete;
BlenderConnection& operator=(const BlenderConnection&)=delete;
BlenderConnection(BlenderConnection&&)=default;
BlenderConnection& operator=(BlenderConnection&&)=default;
bool hasSLERP() const {return m_hasSlerp;}
bool createBlend(const ProjectPath& path, BlendType type);

View File

@ -81,7 +81,7 @@ static void AthenaExc(athena::error::Level level, const char* file,
{
va_list ap;
va_start(ap, fmt);
AthenaLog.reportSource(logvisor::Level(level), file, line, fmt, ap);
AthenaLog.report(logvisor::Level(level), fmt, ap);
va_end(ap);
}

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit 7da2f8e6320fb5b3e1dbb4d1052ef283e1fc8886
Subproject commit db89640172418a67f54c799124e308a7fcfd9578