From 9b6e5a3189311d5704993d41a1fa195e006a57af Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 8 Jan 2010 06:11:56 +0000 Subject: Fix a segfault when exiting before netcode is loaded --- src/main.cpp | 2 +- src/net/net.cpp | 15 ++++++++++++--- src/net/net.h | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 016dfe9e..3c3d3232 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1237,7 +1237,7 @@ int main(int argc, char *argv[]) case STATE_EXIT: logger->log("State: EXIT"); - Net::getGeneralHandler()->unload(); + Net::unload(); break; case STATE_FORCE_QUIT: diff --git a/src/net/net.cpp b/src/net/net.cpp index 50baac73..3b380367 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -121,10 +121,9 @@ Net::TradeHandler *Net::getTradeHandler() namespace Net { - ServerInfo::Type networkType = ServerInfo::UNKNOWN; -} // namespace Net +ServerInfo::Type networkType = ServerInfo::UNKNOWN; -void Net::connectToServer(const ServerInfo &server) +void connectToServer(const ServerInfo &server) { // Remove with ifdefs if (networkType != ServerInfo::UNKNOWN) @@ -189,3 +188,13 @@ void Net::connectToServer(const ServerInfo &server) getLoginHandler()->connect(); } + +void unload() { + GeneralHandler *handler = getGeneralHandler(); + if (handler) + { + handler->unload(); + } +} + +} // namespace Net \ No newline at end of file diff --git a/src/net/net.h b/src/net/net.h index 5e675df7..d6bb7d39 100644 --- a/src/net/net.h +++ b/src/net/net.h @@ -63,6 +63,8 @@ TradeHandler *getTradeHandler(); */ void connectToServer(const ServerInfo &server); +void unload(); + } // namespace Net #endif // NET_H -- cgit v1.2.3-70-g09d2