From 88d8573d4ca1c41e30c68e1e2da9b7eb1ad1b86f Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Tue, 20 Jan 2015 19:18:29 +0100 Subject: [PATCH] Fix crash when loading a dialogue line missing extradata --- src/auto4_lua_assfile.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/auto4_lua_assfile.cpp b/src/auto4_lua_assfile.cpp index b908ecf35..3aef3b769 100644 --- a/src/auto4_lua_assfile.cpp +++ b/src/auto4_lua_assfile.cpp @@ -306,16 +306,19 @@ namespace Automation4 { lua_getfield(L, -1, "extra"); auto type = lua_type(L, -1); - if (type != LUA_TNIL && type != LUA_TTABLE) + if (type == LUA_TTABLE) { + lua_for_each(L, [&] { + if (lua_type(L, -2) != LUA_TSTRING) return; + new_ids.push_back(ass->AddExtradata( + get_string_or_default(L, -2), + get_string_or_default(L, -1))); + }); + std::sort(begin(new_ids), end(new_ids)); + dia->ExtradataIds = std::move(new_ids); + } + else if (type != LUA_TNIL) { error(L, "dialogue extradata must be a table"); - lua_for_each(L, [&] { - if (lua_type(L, -2) != LUA_TSTRING) return; - new_ids.push_back(ass->AddExtradata( - get_string_or_default(L, -2), - get_string_or_default(L, -1))); - }); - std::sort(begin(new_ids), end(new_ids)); - dia->ExtradataIds = std::move(new_ids); + } } else { error(L, "Found line with unknown class: %s", lclass.c_str());