From b826f58497da235d6178dcc741ef745984ad9a4b Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 14 Apr 2016 21:09:22 +0200 Subject: [PATCH] Move scratch buffer for log formatting from stack to static data section * Reduces stack pressure in case applications have manually specified smaller stacks. --- renderdoc/common/common.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/renderdoc/common/common.cpp b/renderdoc/common/common.cpp index 9894b64ad..5f709565a 100644 --- a/renderdoc/common/common.cpp +++ b/renderdoc/common/common.cpp @@ -304,6 +304,9 @@ void rdclogprint_int(const char *str) #endif } +const size_t rdclog_outBufSize = 4*1024; +static char rdclog_outputBuffer[rdclog_outBufSize+1]; + void rdclog_int(LogType type, const char *file, unsigned int line, const char *fmt, ...) { if(type <= RDCLog_First || type >= RDCLog_NumTypes) @@ -337,12 +340,14 @@ void rdclog_int(LogType type, const char *file, unsigned int line, const char *f "Fatal ", }; - const size_t outBufSize = 4*1024; - char outputBuffer[outBufSize+1]; - outputBuffer[outBufSize] = 0; + static Threading::CriticalSection lock; - char *output = outputBuffer; - size_t available = outBufSize; + SCOPED_LOCK(lock); + + rdclog_outputBuffer[rdclog_outBufSize] = rdclog_outputBuffer[0] = 0; + + char *output = rdclog_outputBuffer; + size_t available = rdclog_outBufSize; int numWritten = StringFormat::snprintf(output, available, "%s %s%s%s - ", name, timestamp, location, typestr[type]); @@ -371,5 +376,5 @@ void rdclog_int(LogType type, const char *file, unsigned int line, const char *f *output = '\n'; *(output+1) = 0; - rdclogprint_int(outputBuffer); + rdclogprint_int(rdclog_outputBuffer); }