fix PanicHandler crashing itself with another panic inside sol2

When sol2 does stack::get, it can panic, which causes the stack to
explode, corrupt it, and then any subsequent action crashes the server.
This commit is contained in:
Lion Kortlepel
2026-04-13 18:23:36 +02:00
parent 7089e5da9a
commit 7096fe058a
+10 -1
View File
@@ -440,7 +440,16 @@ void LuaAPI::MP::PrintRaw(sol::variadic_args Args) {
}
int LuaAPI::PanicHandler(lua_State* State) {
beammp_lua_error("PANIC: " + sol::stack::get<std::string>(State, 1));
// panic path: use raw lua c api only; sol2 conversions can raise lua_error
// and re-enter panic recursively.
const int ErrorType = lua_type(State, -1);
if (ErrorType == LUA_TSTRING) {
const char* Message = lua_tostring(State, -1);
beammp_lua_error(std::string("PANIC: ") + (Message ? Message : "(null)"));
} else {
const char* ErrorTypeName = lua_typename(State, ErrorType);
beammp_lua_error(std::string("PANIC: non-string error object (") + (ErrorTypeName ? ErrorTypeName : "unknown") + ")");
}
return 0;
}