Skip to content

Commit

Permalink
Fixed|ServerSystem: Avoid redundant deinitialization
Browse files Browse the repository at this point in the history
Also, if deinitializing at app destruction time, check that the
ServerApp still exists. (Normally doesn't happen as the ServerSystem
is stopped when the server is closing.)
  • Loading branch information
skyjake committed Jul 23, 2013
1 parent b7dc2ca commit e81edf2
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions doomsday/server/src/serversystem.cpp
Expand Up @@ -51,6 +51,8 @@ static de::duint16 Server_ListenPort()

DENG2_PIMPL(ServerSystem)
{
bool inited;

/// Beacon for informing clients that a server is present.
Beacon beacon;
Time lastBeaconUpdateAt;
Expand All @@ -60,9 +62,11 @@ DENG2_PIMPL(ServerSystem)
QMap<Id, RemoteUser *> users;
ShellUsers shellUsers;

Instance(Public *i) : Base(i),
beacon(DEFAULT_UDP_PORT),
serverSock(0)
Instance(Public *i)
: Base(i),
inited(false),
beacon(DEFAULT_UDP_PORT),
serverSock(0)
{}

~Instance()
Expand All @@ -77,6 +81,8 @@ DENG2_PIMPL(ServerSystem)

bool init(duint16 port)
{
// Note: re-initialization is allowed, so we don't check for inited now.

LOG_INFO("Server listening on TCP port ") << port;

deinit();
Expand All @@ -92,6 +98,7 @@ DENG2_PIMPL(ServerSystem)

App_World().audienceForMapChange += shellUsers;

inited = true;
return true;
}

Expand All @@ -107,7 +114,13 @@ DENG2_PIMPL(ServerSystem)

void deinit()
{
App_World().audienceForMapChange -= shellUsers;
if(!inited) return;
inited = false;

if(ServerApp::haveApp())
{
App_World().audienceForMapChange -= shellUsers;
}

beacon.stop();

Expand Down

0 comments on commit e81edf2

Please sign in to comment.