From 378833cefd33e8339854043cb548b47a140f8781 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Tue, 24 Aug 2010 11:19:13 +0200 Subject: [PATCH] mtsimport crash bugfix --- include/mitsuba/core/plugin.h | 6 ++++++ include/mitsuba/render/mipmap.h | 4 ++-- src/converter/mtsimport.cpp | 5 +++++ src/libcore/plugin.cpp | 10 +++++++++- src/libcore/random.cpp | 6 +++++- src/mitsuba/mitsuba.cpp | 2 ++ src/mitsuba/mtssrv.cpp | 3 +++ src/mitsuba/mtsutil.cpp | 2 ++ src/qtgui/main.cpp | 3 +++ 9 files changed, 37 insertions(+), 4 deletions(-) diff --git a/include/mitsuba/core/plugin.h b/include/mitsuba/core/plugin.h index d5818b30..a8b68c05 100644 --- a/include/mitsuba/core/plugin.h +++ b/include/mitsuba/core/plugin.h @@ -79,6 +79,12 @@ public: const Properties &props ); + /// Initializes the global plugin manager instance + static void staticInitialization(); + + /// Free the memory taken by staticInitialization() + static void staticShutdown(); + MTS_DECLARE_CLASS() protected: PluginManager(); diff --git a/include/mitsuba/render/mipmap.h b/include/mitsuba/render/mipmap.h index 877141a2..e474d496 100644 --- a/include/mitsuba/render/mipmap.h +++ b/include/mitsuba/render/mipmap.h @@ -57,6 +57,8 @@ public: /// Return a bitmap representation of the full-resolution image (8 bit/color) Bitmap *getLDRBitmap() const; + + MTS_DECLARE_CLASS() protected: struct ResampleWeight { int firstTexel; @@ -78,8 +80,6 @@ protected: /* Virtual destructor */ virtual ~MIPMap(); - - MTS_DECLARE_CLASS() private: int m_width, m_height; int m_levels; diff --git a/src/converter/mtsimport.cpp b/src/converter/mtsimport.cpp index 461fb84b..5473ef03 100644 --- a/src/converter/mtsimport.cpp +++ b/src/converter/mtsimport.cpp @@ -34,6 +34,7 @@ #include "converter.h" #include #include +#include #if defined(WIN32) #include "../mitsuba/getopt.h" #endif @@ -155,6 +156,7 @@ int ubi_main(int argc, char **argv) { /* Initialize the core framework */ Class::staticInitialization(); + PluginManager::staticInitialization(); Statistics::staticInitialization(); Thread::staticInitialization(); Logger::staticInitialization(); @@ -195,6 +197,8 @@ int ubi_main(int argc, char **argv) { ref session = Session::create(); ref device = Device::create(session); ref renderer = Renderer::create(session); + renderer->setLogLevel(ETrace); + renderer->setWarnLogLevel(ETrace); session->init(); device->init(); @@ -233,6 +237,7 @@ int ubi_main(int argc, char **argv) { Logger::staticShutdown(); Thread::staticShutdown(); Statistics::staticShutdown(); + PluginManager::staticShutdown(); Class::staticShutdown(); return retval; diff --git a/src/libcore/plugin.cpp b/src/libcore/plugin.cpp index b3e9d6e2..4a2b3083 100644 --- a/src/libcore/plugin.cpp +++ b/src/libcore/plugin.cpp @@ -96,7 +96,7 @@ Plugin::~Plugin() { // Plugin manager // ----------------------------------------------------------------------- -ref PluginManager::m_instance = new PluginManager(); +ref PluginManager::m_instance = NULL; PluginManager::PluginManager() { m_mutex = new Mutex(); @@ -172,5 +172,13 @@ void PluginManager::ensurePluginLoaded(const std::string &name) { Log(EError, "Plugin \"%s\" not found!", name.c_str()); } +void PluginManager::staticInitialization() { + m_instance = new PluginManager(); +} + +void PluginManager::staticShutdown() { + m_instance = NULL; +} + MTS_IMPLEMENT_CLASS(PluginManager, false, Object) MTS_NAMESPACE_END diff --git a/src/libcore/random.cpp b/src/libcore/random.cpp index 9c9bc604..c5631eb9 100644 --- a/src/libcore/random.cpp +++ b/src/libcore/random.cpp @@ -63,12 +63,16 @@ Random::Random() { #if defined(WIN32) seed(); #else +#if 0 uint64_t buf[MT_N]; + memset(buf, 0, MT_N * sizeof(uint64_t)); /* Make GCC happy */ ref urandom = new FileStream("/dev/urandom", FileStream::EReadOnly); urandom->readULongArray(buf, MT_N); -// seed(buf, MT_N); + seed(buf, MT_N); +#else seed(); #endif +#endif } Random::Random(Random *random) { diff --git a/src/mitsuba/mitsuba.cpp b/src/mitsuba/mitsuba.cpp index 81fa322b..e383e462 100644 --- a/src/mitsuba/mitsuba.cpp +++ b/src/mitsuba/mitsuba.cpp @@ -321,6 +321,7 @@ int ubi_main(int argc, char **argv) { int main(int argc, char **argv) { /* Initialize the core framework */ Class::staticInitialization(); + PluginManager::staticInitialization(); Statistics::staticInitialization(); Thread::staticInitialization(); Logger::staticInitialization(); @@ -390,6 +391,7 @@ int main(int argc, char **argv) { Logger::staticShutdown(); Thread::staticShutdown(); Statistics::staticShutdown(); + PluginManager::staticShutdown(); Class::staticShutdown(); #ifdef WIN32 diff --git a/src/mitsuba/mtssrv.cpp b/src/mitsuba/mtssrv.cpp index 44fb56cb..14d20e1f 100644 --- a/src/mitsuba/mtssrv.cpp +++ b/src/mitsuba/mtssrv.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -354,6 +355,7 @@ int ubi_main(int argc, char **argv) { int main(int argc, char **argv) { /* Initialize the core framework */ Class::staticInitialization(); + PluginManager::staticInitialization(); Statistics::staticInitialization(); Thread::staticInitialization(); Logger::staticInitialization(); @@ -413,6 +415,7 @@ int main(int argc, char **argv) { Logger::staticShutdown(); Thread::staticShutdown(); Statistics::staticShutdown(); + PluginManager::staticShutdown(); Class::staticShutdown(); diff --git a/src/mitsuba/mtsutil.cpp b/src/mitsuba/mtsutil.cpp index 18dc17fd..1e8e334c 100644 --- a/src/mitsuba/mtsutil.cpp +++ b/src/mitsuba/mtsutil.cpp @@ -303,6 +303,7 @@ int ubi_main(int argc, char **argv) { int main(int argc, char **argv) { /* Initialize the core framework */ Class::staticInitialization(); + PluginManager::staticInitialization(); Statistics::staticInitialization(); Thread::staticInitialization(); Logger::staticInitialization(); @@ -372,6 +373,7 @@ int main(int argc, char **argv) { Logger::staticShutdown(); Thread::staticShutdown(); Statistics::staticShutdown(); + PluginManager::staticShutdown(); Class::staticShutdown(); #ifdef WIN32 diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index d7401113..328a797f 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #if defined(__OSX__) #include #endif @@ -77,6 +78,7 @@ int main(int argc, char *argv[]) { /* Initialize the core framework */ Class::staticInitialization(); + PluginManager::staticInitialization(); Statistics::staticInitialization(); Thread::staticInitialization(); Logger::staticInitialization(); @@ -204,6 +206,7 @@ int main(int argc, char *argv[]) { Logger::staticShutdown(); Thread::staticShutdown(); Statistics::staticShutdown(); + PluginManager::staticShutdown(); Class::staticShutdown(); return retval;