limited win32 stack-trace size
authorspog <spog>
Sun, 9 Apr 2006 18:16:41 +0000 (18:16 +0000)
committerspog <spog>
Sun, 9 Apr 2006 18:16:41 +0000 (18:16 +0000)
git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@46 8a3a26a2-13c4-0310-b231-cf6edde360e5

19 files changed:
contrib/prtview/prtview.cpp
include/modulesystem.h
plugins/archivepak/plugin.cpp
plugins/archivewad/plugin.cpp
plugins/archivezip/plugin.cpp
plugins/entity/plugin.cpp
plugins/image/image.cpp
plugins/imagehl/imagehl.cpp
plugins/imagepng/plugin.cpp
plugins/imageq2/imageq2.cpp
plugins/mapq3/plugin.cpp
plugins/mapxml/plugin.cpp
plugins/md3model/plugin.cpp
plugins/model/plugin.cpp
plugins/sample/sample.cpp
plugins/shaders/plugin.cpp
plugins/vfspk3/vfspk3.cpp
radiant/console.cpp
radiant/main.cpp

index 2d4cebb..34c6e70 100644 (file)
@@ -320,10 +320,7 @@ SingletonPrtViewPluginModule g_PrtViewPluginModule;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_PrtViewPluginModule.selfRegister();
 }
index 7cb6d3f..4c5495d 100644 (file)
@@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #define INCLUDED_MODULESYSTEM_H
 
 #include "generic/static.h"
+#include "debugging/debugging.h"
 
 #if defined(WIN32)
 #define RADIANT_DLLEXPORT __stdcall
@@ -94,6 +95,16 @@ inline ModuleServer& globalModuleServer()
 }
 
 
+inline void initialiseModule(ModuleServer& server)
+{
+  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
+  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
+  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
+  GlobalModuleServer::instance().set(server);
+}
+
+
+
 template<typename Type>
 class Modules
 {
index c141523..d73b0ef 100644 (file)
@@ -52,10 +52,7 @@ ArchivePakModule g_ArchivePakModule;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_ArchivePakModule.selfRegister();
 }
index cf5f691..a27c459 100644 (file)
@@ -52,10 +52,7 @@ ArchiveWadModule g_ArchiveWadModule;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_ArchiveWadModule.selfRegister();
 }
index 59e2511..82a5a2a 100644 (file)
@@ -75,10 +75,7 @@ ArchivePK4Module g_ArchivePK4Module;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_ArchiveZipModule.selfRegister();
   g_ArchivePK4Module.selfRegister();
index 947befb..58ace89 100644 (file)
@@ -151,10 +151,7 @@ EntityDoom3Module g_EntityDoom3Module;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_EntityQ3Module.selfRegister();
   g_EntityWolfModule.selfRegister();
index 2a4afb2..4436dde 100644 (file)
@@ -149,10 +149,7 @@ ImageDDSModule g_ImageDDSModule;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_ImageTGAModule.selfRegister();
   g_ImageJPGModule.selfRegister();
index 7cbe07a..af05104 100644 (file)
@@ -105,10 +105,7 @@ ImageSpriteModule g_ImageSpriteModule;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_ImageHLWModule.selfRegister();
   g_ImageMipModule.selfRegister();
index 1247ba9..426c4f0 100644 (file)
@@ -198,10 +198,7 @@ ImagePNGModule g_ImagePNGModule;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_ImagePNGModule.selfRegister();
 }
index 338b5e2..dfd6446 100644 (file)
@@ -106,10 +106,7 @@ ImageM32Module g_ImageM32Module;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_ImageWalModule.selfRegister();
   g_ImageM8Module.selfRegister();
index 8e031ed..a11dc4a 100644 (file)
@@ -646,10 +646,7 @@ MapVMFModule g_MapVMFModule;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_MapDoom3Module.selfRegister();
   g_MapQuake4Module.selfRegister();
index 083cef8..6bb09be 100644 (file)
@@ -84,10 +84,7 @@ MapXMLModule g_MapXMLModule;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_MapXMLModule.selfRegister();
 }
index 42c2a92..dbdff93 100644 (file)
@@ -236,10 +236,7 @@ ModelMD5Module g_ModelMD5Module;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_ModelMD3Module.selfRegister();
   g_ModelMD2Module.selfRegister();
index 278388f..e032e39 100644 (file)
@@ -169,10 +169,7 @@ PicoModelModules g_PicoModelModules;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   pico_initialise();
 
index cec08dd..80900b1 100644 (file)
@@ -89,10 +89,7 @@ SingletonSamplePluginModule g_SamplePluginModule;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_SamplePluginModule.selfRegister();
 }
index 6732ca6..6ef23c3 100644 (file)
@@ -149,10 +149,7 @@ ShadersQuake4Module g_ShadersQuake4Module;
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_ShadersQ3Module.selfRegister();
   g_ShadersDoom3Module.selfRegister();
index ed250e3..e7fca37 100644 (file)
@@ -79,10 +79,7 @@ ArchiveModules& FileSystemQ3API_getArchiveModules()
 
 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules(ModuleServer& server)
 {
-  GlobalErrorStream::instance().setOutputStream(server.getErrorStream());
-  GlobalOutputStream::instance().setOutputStream(server.getOutputStream());
-  GlobalDebugMessageHandler::instance().setHandler(server.getDebugMessageHandler());
-  GlobalModuleServer::instance().set(server);
+  initialiseModule(server);
 
   g_FileSystemQ3Module.selfRegister();
 }
index f47c66d..f48a987 100644 (file)
@@ -155,7 +155,7 @@ public:
 
 std::size_t Sys_Print(int level, const char* buf, std::size_t length)
 {
-  bool contains_newline = strchr(buf, '\n') != 0;
+  bool contains_newline = std::find(buf, buf+length, '\n') != buf+length;
 
   if(level == SYS_ERR)
   {
index dc76466..b66728a 100644 (file)
@@ -232,6 +232,41 @@ public:
   }
 };
 
+class LineLimitedTextOutputStream : public TextOutputStream
+{
+  TextOutputStream& outputStream;
+  std::size_t count;
+public:
+  LineLimitedTextOutputStream(TextOutputStream& outputStream, std::size_t count)
+    : outputStream(outputStream), count(count)
+  {
+  }
+  std::size_t write(const char* buffer, std::size_t length)
+  {
+    if(count != 0)
+    {
+      const char* p = buffer;
+      const char* end = buffer+length;
+      for(;;)
+      {
+        p = std::find(p, end, '\n');
+        if(p == end)
+        {
+          break;
+        }
+        ++p;
+        if(--count == 0)
+        {
+          length = p - buffer;
+          break;
+        }
+      }
+      outputStream.write(buffer, length);
+    }
+    return length;
+  }
+};
+
 class PopupDebugMessageHandler : public DebugMessageHandler
 {
   StringOutputStream m_buffer;
@@ -248,7 +283,8 @@ public:
   bool handleMessage()
   {
     getOutputStream() << "----------------\n";
-    write_stack_trace(getOutputStream());
+    LineLimitedTextOutputStream outputStream(getOutputStream(), 24);
+    write_stack_trace(outputStream);
     getOutputStream() << "----------------\n";
     if(!m_lock.locked())
     {