Skip to content

Commit

Permalink
libdeng2: Clear log buffer before unloading any library
Browse files Browse the repository at this point in the history
It is possible that the library has created log entries that are still
in the log buffer. Previously this was done in 'engine', but now since
libdeng2 is in control of all plugin loading and unloading, it can
clear the log buffer in one central place (just before closing the
library).
  • Loading branch information
skyjake committed Dec 18, 2012
1 parent 598d45d commit f0a8580
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
3 changes: 0 additions & 3 deletions doomsday/engine/src/dd_main.cpp
Expand Up @@ -1475,9 +1475,6 @@ bool DD_ChangeGame(de::Game& game, bool allowReload = false)
}
)

// Remove all entries; some may have been created by the game plugin (if it used libdeng2 C++ API).
LogBuffer_Clear();

Library_ReleaseGames();

char buf[256];
Expand Down
3 changes: 0 additions & 3 deletions doomsday/engine/src/dd_plugin.c
Expand Up @@ -146,9 +146,6 @@ void Plug_UnloadAll(void)
{
int i;

// Remove all entries; some may have been created by the plugins.
LogBuffer_Clear();

for(i = 0; i < MAX_PLUGS && hInstPlug[i]; ++i)
{
unloadPlugin(&hInstPlug[i]);
Expand Down
4 changes: 4 additions & 0 deletions doomsday/libdeng2/include/de/core/logbuffer.h
Expand Up @@ -73,6 +73,10 @@ class DENG2_PUBLIC LogBuffer : public QObject, public Lockable, DENG2_OBSERVES(F
*/
void add(LogEntry *entry);

/**
* Clears the buffer by deleting all entries from memory. However, they are
* first flushed, so the no entries are lost.
*/
void clear();

/**
Expand Down
5 changes: 5 additions & 0 deletions doomsday/libdeng2/src/core/library.cpp
Expand Up @@ -20,6 +20,7 @@
#include "de/libdeng2.h"
#include "de/Library"
#include "de/Log"
#include "de/LogBuffer"

#if defined(UNIX) && defined(DENG2_QT_4_7_OR_NEWER) && !defined(DENG2_QT_4_8_OR_NEWER)
# define DENG2_USE_DLOPEN
Expand Down Expand Up @@ -117,6 +118,10 @@ Library::~Library()
DENG2_SYMBOL(deng_ShutdownPlugin)();
}

// The log buffer may contain log entries built by the library; those
// entries contain pointers to functions that are about to disappear.
LogBuffer::appBuffer().clear();

#ifndef DENG2_USE_DLOPEN
d->library->unload();
delete d->library;
Expand Down

0 comments on commit f0a8580

Please sign in to comment.