From 558ff54cb0be460f9624e3d0bc865e9d63d1840d Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 3 Aug 2023 20:45:44 -0300 Subject: [PATCH] [lua] Add traceback info when a doc object is deleted and we try to use it A reference to a doc object (Sprite, Layer, Cel, etc.) is done through its ID in the scripting engine, when we try to access it from a script that element might be already deleted. Previously we displayed the a message like "Using a nil 'Cel' object". With this change we show the traceback and a "Tried to access a deleted 'Cel'" message. --- src/app/script/docobj.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/script/docobj.h b/src/app/script/docobj.h index 8974234dd..2a33acc84 100644 --- a/src/app/script/docobj.h +++ b/src/app/script/docobj.h @@ -41,7 +41,11 @@ template T* check_docobj(lua_State* L, T* obj) { if (obj) return obj; else { - luaL_error(L, "Using a nil '%s' object", get_mtname()); + luaL_traceback(L, L, nullptr, 1); + const char* traceback = lua_tostring(L, -1); + luaL_error(L, "%s: Tried to access a deleted '%s'", + traceback ? traceback: "", + get_mtname()); ASSERT(false); // unreachable code return nullptr; }