Page 1 of 1

[SOLVED] Disabling log file

Posted: Mon Jan 18, 2010 19:02
by pianoman
Hi, I want to prevent the creation of the CEGUI log file, and I saw a post on disabling CEGUI log file creation ( viewtopic.php?f=10&t=3435&p=15557&hilit=disable+logging#p15557 ), so I followed the example code posted there and put the following in my main.cpp:

Code: Select all

//// Disable logging in CEGUI for Release build
#ifndef _DEBUG
class CeguiNonLogger : public CEGUI::Logger{
   void logEvent (const CEGUI::String&, CEGUI::LoggingLevel){}
   void setLogFilename(const CEGUI::String&, bool){}
};
CeguiNonLogger g_ceguiNonLogger;
#endif


But when I do that, when exiting my app I get a failed assertion at CEGUISingleton.h, line 77:

Code: Select all

   ~Singleton( void )
        {  assert( ms_Singleton );  ms_Singleton = 0;  }


Do I need to postpone the instantiation of my logger until a certain point or something?

Edit: I tried making my logger a member variable of my app's main class, and I still had the same problem; then I made it a pointer and instantiated it the line before creating the CEGUI renderer and system objects, and there was no assertion failure :) . But this is also a memory leak, right? :? And I'm just avoiding the assertion by avoiding the CEGUISingleton destructor since I never delete the logger? Or does the logger automatically get deleted, which is why it is 0 in the destructor when I don't heap-allocate it or delete it myself? :?:

Re: Disabling log file

Posted: Tue Jan 19, 2010 09:49
by CrazyEddie
Hi,

This is a bug in 0.6.x (should be fixed in 0.7.x).

Basically in 0.6.x, within the CEGUI::System destructor, the logger is always deleted by:

Code: Select all

delete CEGUI::Logger::getSingletonPtr();

regardless of who created it and how (which makes this a particularly nasty bug).

As such, to do this in 0.6.x you must ensure that the logger is created via new, and is not deleted (since the system will do it). However, if you intend upgrading to 0.7.x at any time, that code then becomes a leak, since in 0.7.x we have the correct behaviour (i.e you create it, you delete it).

HTH

CE.

Re: Disabling log file

Posted: Wed Jan 20, 2010 00:50
by pianoman
Perfect. Thanks! :D