From a5d131cc1f3c3db4aa219d05aa49906624b54239 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Fri, 26 Feb 2016 21:19:09 -0500 Subject: [PATCH] Fix potential crash when using an [engine]name=lua --- src/ai/lua/core.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ai/lua/core.cpp b/src/ai/lua/core.cpp index b2be60c3d784..1c7afd280dbe 100644 --- a/src/ai/lua/core.cpp +++ b/src/ai/lua/core.cpp @@ -84,6 +84,14 @@ void lua_ai_context::set_persistent_data(const config &cfg) lua_pushlightuserdata(L, static_cast(const_cast(&aisKey))); lua_rawget(L, LUA_REGISTRYINDEX); lua_rawgeti(L, -1, num_); + + if(lua_isnoneornil(L, -1)) { + // Just in case the self table wasn't initialized. + lua_pop(L, 1); + lua_newtable(L); + lua_rawseti(L, -2, num_); + lua_rawgeti(L, -1, num_); + } luaW_pushconfig(L, cfg); lua_setfield(L, -2, "data");