replace Server smart pointer with conventional one to gain control over dtor call...
authorsapier <Sapier at GMX dot net>
Sun, 7 Apr 2013 17:41:12 +0000 (19:41 +0200)
committerkwolekr <kwolekr@minetest.net>
Mon, 8 Apr 2013 02:42:36 +0000 (22:42 -0400)
src/game.cpp
src/main.cpp

index 65feb50bf308921ed0c43eb00859cf9f74afdd56..4f6eb472d904156a0be1bc6c7367f3917d635bab 100644 (file)
@@ -992,6 +992,9 @@ void the_game(
                sound_is_dummy = true;
        }
 
+       Server *server = NULL;
+
+       try{
        // Event manager
        EventManager eventmgr;
 
@@ -1007,9 +1010,8 @@ void the_game(
 
        /*
                Create server.
-               SharedPtr will delete it when it goes out of scope.
        */
-       SharedPtr<Server> server;
+
        if(address == ""){
                draw_load_screen(L"Creating server...", driver, font);
                infostream<<"Creating server"<<std::endl;
@@ -1018,7 +1020,6 @@ void the_game(
                server->start(port);
        }
 
-       try{
        do{ // Client scope (breakable do-while(0))
        
        /*
@@ -3290,10 +3291,25 @@ void the_game(
                                L" running a different version of Minetest.";
                errorstream<<wide_to_narrow(error_message)<<std::endl;
        }
+       catch(ServerError &e)
+       {
+               error_message = narrow_to_wide(e.what());
+               errorstream<<wide_to_narrow(error_message)<<std::endl;
+       }
+       catch(ModError &e)
+       {
+               errorstream<<e.what()<<std::endl;
+               error_message = narrow_to_wide(e.what()) + wgettext("\nCheck debug.txt for details.");
+       }
+
+
        
        if(!sound_is_dummy)
                delete sound;
 
+       //has to be deleted first to stop all server threads
+       delete server;
+
        delete tsrc;
        delete shsrc;
        delete nodedef;
index 08af6a37d8bd59794924cb89c8b68690b1d5d52f..b0cabfe81ce2be2a116d9bfb5ef2ccdec3210cf5 100644 (file)
@@ -1902,16 +1902,6 @@ int main(int argc, char *argv[])
                        error_message = wgettext("Connection error (timed out?)");
                        errorstream<<wide_to_narrow(error_message)<<std::endl;
                }
-               catch(ServerError &e)
-               {
-                       error_message = narrow_to_wide(e.what());
-                       errorstream<<wide_to_narrow(error_message)<<std::endl;
-               }
-               catch(ModError &e)
-               {
-                       errorstream<<e.what()<<std::endl;
-                       error_message = narrow_to_wide(e.what()) + wgettext("\nCheck debug.txt for details.");
-               }
 #ifdef NDEBUG
                catch(std::exception &e)
                {