Skip to content

Commit

Permalink
Fixed|libdoomsday: Avoid a crash when reseting engine state
Browse files Browse the repository at this point in the history
Map observes when its manifest is deleted.

IssueID #2144
  • Loading branch information
skyjake committed Dec 25, 2015
1 parent 501aa9b commit b67126b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion doomsday/apps/libdoomsday/src/world/map.cpp
@@ -1,6 +1,6 @@
/** @file world.cpp Base for world maps.
*
* @authors Copyright © 2014-2015 Daniel Swanson <danij@dengine.net>
* @authors Copyright 2014-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -24,6 +24,7 @@ using namespace de;
namespace world {

DENG2_PIMPL(Map)
, DENG2_OBSERVES(Record, Deletion)
{
res::MapManifest *manifest = nullptr; ///< Not owned, may be @c nullptr.

Expand All @@ -34,6 +35,15 @@ DENG2_PIMPL(Map)
{
DENG2_FOR_PUBLIC_AUDIENCE2(Deletion, i) i->mapBeingDeleted(self);
}

void recordBeingDeleted(Record &record)
{
// The manifest is not owned by us, it may be deleted by others.
if(manifest == &record)
{
manifest = nullptr;
}
}

DENG2_PIMPL_AUDIENCE(Deletion)
};
Expand Down Expand Up @@ -66,7 +76,11 @@ res::MapManifest &Map::manifest() const

void Map::setManifest(res::MapManifest *newManifest)
{
if(d->manifest) d->manifest->audienceForDeletion() -= d;

d->manifest = newManifest;

if(d->manifest) d->manifest->audienceForDeletion() += d;
}

} // namespace world

0 comments on commit b67126b

Please sign in to comment.