From d6d045aad45c4c5fc4eb3814c131e6c25fb49fe8 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Wed, 23 Apr 2025 21:41:18 +0200 Subject: [PATCH] Script: avoid fatal error in deprecated func handler --- src/script/lua_api/l_base.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index 8c2affe81..c25c80724 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -123,14 +123,18 @@ int ModApiBase::l_deprecated_function(lua_State *L, const char *good, const char u64 start_time = porting::getTimeUs(); lua_Debug ar; + std::string backtrace; // Get caller name with line and script backtrace - FATAL_ERROR_IF(!lua_getstack(L, 1, &ar), "lua_getstack() failed"); - FATAL_ERROR_IF(!lua_getinfo(L, "Sl", &ar), "lua_getinfo() failed"); + if (lua_getstack(L, 1, &ar) && lua_getinfo(L, "Sl", &ar)) { + // Get backtrace and hash it to reduce the warning flood + backtrace = ar.short_src; + backtrace.append(":").append(std::to_string(ar.currentline)); + } else { + backtrace = " "; + backtrace.append(script_get_backtrace(L)); + } - // Get backtrace and hash it to reduce the warning flood - std::string backtrace = ar.short_src; - backtrace.append(":").append(std::to_string(ar.currentline)); u64 hash = murmur_hash_64_ua(backtrace.data(), backtrace.length(), 0xBADBABE); if (std::find(deprecated_logged.begin(), deprecated_logged.end(), hash)