Crash on the wxLog->Flush

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
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Crash on the wxLog->Flush

Post by ONEEYEMAN »

Hi, ALL,
Never needed to wx logging, before...

Here is my code:

Code: Select all

class Dlg : public wxDialog
{
public::
    Dlg();
    ~Dlg();
private::
    std::ofstream log;
    wxLog **logger;
};

Dlg::Dlg()
{
    log.open( "mylogfile.log" );
    logger = new wxLogStream( &log );
    wxLog::SetActiveTarget( logger );
}

Dlg::~Dlg()
{
    log.close();
}
The dialog shows up, performs what needs to be done, but when I click "Cancel" button to cancel the dialog, I'm getting a crush on the wxLog->Flush().

What am I doing wrong?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Crash on the wxLog->Flush

Post by doublemax »

You need to delete the new logtarget first and restore the old one.

Code: Select all

  wxLog* oldLog = wxLog::SetActiveTarget(new wxLogStderr);

  [...] using log here

  delete wxLog::SetActiveTarget(oldLog);
Use the source, Luke!
Post Reply