summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_env.cpp
diff options
context:
space:
mode:
authorRogier <rogier777@gmail.com>2016-07-25 18:39:29 +0200
committerparamat <mat.gregory@virginmedia.com>2016-10-16 01:13:16 +0100
commit4b17105dc45976e399dab68f85b3030fa27f0ae2 (patch)
treee4df3345d4c8af05427754db97ea6e66031088df /src/script/lua_api/l_env.cpp
parentadad6e0a1c2bb6cd5e56db26d660fa9342cf0d0e (diff)
downloadminetest-4b17105dc45976e399dab68f85b3030fa27f0ae2.tar.gz
minetest-4b17105dc45976e399dab68f85b3030fa27f0ae2.tar.bz2
minetest-4b17105dc45976e399dab68f85b3030fa27f0ae2.zip
Emergeblocks: Fix occasional crash
Modification of the emergeblocks internal state was not protected by a lock, causing a race condition. This can be reproduced by repeatedly running emergeblocks for an already-generated section of the map (with multiple emerge threads).
Diffstat (limited to 'src/script/lua_api/l_env.cpp')
-rw-r--r--src/script/lua_api/l_env.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index f6ea23e95..68d10308c 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -137,6 +137,10 @@ void LuaEmergeAreaCallback(v3s16 blockpos, EmergeAction action, void *param)
assert(state->script != NULL);
assert(state->refcount > 0);
+ // state must be protected by envlock
+ Server *server = state->script->getServer();
+ MutexAutoLock envlock(server->m_env_mutex);
+
state->refcount--;
state->script->on_emerge_area_completion(blockpos, action, state);