Problem in wxApp destructor with wxLogGui Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Problem in wxApp destructor with wxLogGui

Post by extreme001 » Mon Mar 14, 2011 10:02 pm

Hi!

In my destructor of my derived wxApp is everything ok. First delete, then i set my variable to NULL.

But after leaving the destructor it shows an unhandled exception...violation reading location 0x000000e8.
It stops at xstring::bool empty, that comes from wxString::empty(), from wxAppConsole::GetAppDisplayName(), from wxLogGui::GetTitle(), from wxLogGui::Flush(), from wxLogGui::FlushActive.

In the OnInit-Function of my i set the logtarget to a file with this code:

Code: Select all

// set logging logging to file
	m_logFile = fopen(logfilename.GetData(), "a");
	m_StandardLog = new wxLogStderr(m_logFile);
	wxLog::SetActiveTarget(m_StandardLog);
what's the error? Any ideas?

Thank you

extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Post by extreme001 » Mon Mar 14, 2011 10:05 pm

I know what the error is trying to tell me, but i have no idea how to release/free the log-object. Is it possible to destroy the log-object in destructor?

User avatar
doublemax
Moderator
Moderator
Posts: 15828
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Mon Mar 14, 2011 10:33 pm

Try moving the code from the dtor to wxApp::OnExit
Use the source, Luke!

catalin
Moderator
Moderator
Posts: 1597
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin » Mon Mar 14, 2011 10:40 pm

I think your problem is that you delete the active log target, which is kinda wrong. IIRC wxLog will delete the active target if it has one, so you shouldn't need to do it explicitly, but to be sure you can just revert to the default (NULL) log target and delete yours:
delete wxLog::SetActiveTarget(NULL);
or for easier reading:
wxLog::SetActiveTarget(NULL);
delete m_StandardLog;
Just make sure you do not try to destroy it twice by calling delete m_StandardLog somewhere else.

extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Post by extreme001 » Tue Mar 15, 2011 10:53 am

Thank you guys! I got it working by moving the code into OnExit() ;-) and yes, i deleted the m_standardlog before, but i searched for the wrong term in my sources.

Now i have to find out why Visual Studio shows a corruption of heap.

Have a nice day.

Post Reply