From e81edf28f8b4c9a3504badd4ef644dce975e0675 Mon Sep 17 00:00:00 2001 From: skyjake Date: Tue, 23 Jul 2013 08:59:52 +0300 Subject: [PATCH] Fixed|ServerSystem: Avoid redundant deinitialization 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.) --- doomsday/server/src/serversystem.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/doomsday/server/src/serversystem.cpp b/doomsday/server/src/serversystem.cpp index 5f839617b1..414e0b1897 100644 --- a/doomsday/server/src/serversystem.cpp +++ b/doomsday/server/src/serversystem.cpp @@ -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; @@ -60,9 +62,11 @@ DENG2_PIMPL(ServerSystem) QMap 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() @@ -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(); @@ -92,6 +98,7 @@ DENG2_PIMPL(ServerSystem) App_World().audienceForMapChange += shellUsers; + inited = true; return true; } @@ -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();