Fix crash when a error occurs in a globalstep callback
authorShadowNinja <shadowninja@minetest.net>
Mon, 3 Feb 2014 23:15:03 +0000 (18:15 -0500)
committerShadowNinja <shadowninja@minetest.net>
Mon, 3 Feb 2014 23:15:03 +0000 (18:15 -0500)
src/script/cpp_api/s_env.cpp

index ef3a1dddf77cca3df4b9bcc11824088671207cf6..2c2198edf1c5eb42e0f07e5e4b4e107301574309 100644 (file)
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "environment.h"
 #include "mapgen.h"
 #include "lua_api/l_env.h"
+#include "server.h"
 
 void ScriptApiEnv::environment_OnGenerated(v3s16 minp, v3s16 maxp,
                u32 blockseed)
@@ -50,7 +51,11 @@ void ScriptApiEnv::environment_Step(float dtime)
        lua_getfield(L, -1, "registered_globalsteps");
        // Call callbacks
        lua_pushnumber(L, dtime);
-       script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST);
+       try {
+               script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST);
+       } catch (LuaError &e) {
+               getServer()->setAsyncFatalError(e.what());
+       }
 }
 
 void ScriptApiEnv::environment_OnMapgenInit(MapgenParams *mgparams)