From 7baf7ff61357393e8488ce789a60693076950050 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 4 Apr 2011 07:15:02 +0200 Subject: [PATCH] mtsutil crash bugfix --- src/libcore/object.cpp | 22 ++++++++++++++++++++-- src/mitsuba/mtsutil.cpp | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/libcore/object.cpp b/src/libcore/object.cpp index 7e29d752..39841a6b 100644 --- a/src/libcore/object.cpp +++ b/src/libcore/object.cpp @@ -18,6 +18,8 @@ #include +//#define DEBUG_ALLOCATIONS 1 + MTS_NAMESPACE_BEGIN Class *Object::m_theClass = new Class("Object", false, ""); @@ -27,6 +29,11 @@ Object::Object() } void Object::incRef() const { +#if defined(DEBUG_ALLOCATIONS) + if (Class::rttiIsInitialized()) + cout << this << ": Increasing reference count (" << getClass()->getName() << ") -> " + << m_refCount + 1 << endl; +#endif #if defined(_WIN32) InterlockedIncrement(&m_refCount); #else @@ -35,17 +42,28 @@ void Object::incRef() const { } void Object::decRef() const { +#if defined(DEBUG_ALLOCATIONS) + if (Class::rttiIsInitialized()) { + cout << this << ": Decreasing reference count (" << getClass()->getName() << ") -> " + << m_refCount - 1 << endl; + } +#endif #if defined(_WIN32) int count = InterlockedDecrement(&m_refCount); #else int count = __sync_sub_and_fetch(&m_refCount, 1); #endif AssertEx(count >= 0, "Reference count is below zero!"); - if (count == 0) + if (count == 0) { +#if defined(DEBUG_ALLOCATIONS) + if (Class::rttiIsInitialized()) + cout << this << ": Deleting an instance of " << + getClass()->getName() << endl; +#endif delete this; + } } - const Class *Object::getClass() const { return m_theClass; } diff --git a/src/mitsuba/mtsutil.cpp b/src/mitsuba/mtsutil.cpp index a546d0ad..ce9b0247 100644 --- a/src/mitsuba/mtsutil.cpp +++ b/src/mitsuba/mtsutil.cpp @@ -343,6 +343,7 @@ int mtsutil(int argc, char **argv) { ref utility = plugin->createUtility(); int retval = utility->run(argc-optind, argv+optind); + scheduler->pause(); utility = NULL; delete plugin; return retval;