crash in case of invalid api usage

This commit is contained in:
tour 2024-03-17 14:01:05 +01:00
parent e237bf0e22
commit e6a950c30a
2 changed files with 13 additions and 0 deletions

View File

@ -5,8 +5,16 @@ areas.registered_on_adds = {}
areas.registered_on_removes = {}
areas.registered_on_moves = {}
areas.callback_origins = {}
function areas:registerProtectionCondition(func)
table.insert(areas.registered_protection_conditions, func)
local debug_info = debug.getinfo(func, "S")
areas.callback_origins[func] = {
mod = core.get_current_modname() or "??",
source = debug_info.short_src or "??",
line = debug_info.linedefined or "??"
}
end
function areas:registerOnAdd(func)

View File

@ -222,6 +222,11 @@ function areas:canPlayerAddArea(pos1, pos2, name)
allowed = false
-- save the first error that occurred
errMsg = errMsg or msg
elseif res ~= nil then
local origin = areas.callback_origins[areas.registered_protection_conditions[i]]
error("\n[Mod] areas: Invalid api usage from mod '" ..
origin.mod .. "' in callback registerProtectionCondition() at " ..
origin.source .. ":" .. origin.line)
end
end