Putting this in #questions since I’m not 100% sure if it’s me or Defold doing something wrong.
A library that I’m working on uses a native extension to register a log listener that passes the messages to a Lua callback for it to handle. This all works great, except that it eventually crashes the engine with a different error message each time! It’s usually a failed DM_LUA_STACK_CHECK()
or a similar Lua-related assertion. Sometimes you get fun errors like this where the render script can’t access render functions :
ERROR:SCRIPT: builtins/render/default.render_script:82: You can only access render.* functions and values from a render script instance (.render_script file)
stack traceback:
[C]:-1: in function clear
builtins/render/default.render_script:82: in function <builtins/render/default.render_script:71>
Anyways, almost all of the code is from official examples and I (a non-C++ programmer) can’t see anything wrong after looking for quite a while. Here’s the relevant extension code:
dmScript::LuaCallbackInfo* cb = 0;
static void LogListener(LogSeverity severity, const char* domain, const char* message) {
if (!dmScript::IsCallbackValid(cb))
return;
lua_State* L = dmScript::GetCallbackLuaContext(cb);
DM_LUA_STACK_CHECK(L, 0);
if (!dmScript::SetupCallback(cb)) {
dmLogError("Failed to set up callback");
return;
}
lua_pushstring(L, domain);
lua_pushstring(L, message);
dmScript::PCall(L, 3, 0);
dmScript::TeardownCallback(cb);
}
static int LuaRegisterCallback(lua_State* L) {
DM_LUA_STACK_CHECK(L, 0);
cb = dmScript::CreateCallback(L, 1);
return 0;
}
I’ve also made a minimal project that has the same error, just run it and wait a few seconds:
example.zip (4.0 KB)
In case it’s important, I’m running the latest Fedora Silverblue (37.20230227.0) and Defold 1.4.3: