fix sandbox app script loading and timer execution
- Add relative path resolution for filesystem-loaded documents in kernel.cpp - SetDocumentBasePath() tracks document directory for relative resource resolution - ResolvePath() resolves relative paths like "app.lua" against document base path - Fix RmlUi context name lookup in sandbox test app (use "default" not "main") - Add debug logging to timer_manager.cpp to trace timer creation and execution Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,13 @@
|
||||
|
||||
#include <lua.hpp>
|
||||
#include <algorithm>
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
#define TIMER_LOG(...) __android_log_print(ANDROID_LOG_INFO, "MosisOS", __VA_ARGS__)
|
||||
#else
|
||||
#include <cstdio>
|
||||
#define TIMER_LOG(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
namespace mosis {
|
||||
|
||||
@@ -64,8 +71,12 @@ TimerId TimerManager::SetInterval(lua_State* L, const std::string& app_id,
|
||||
int callback_ref, int interval_ms) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
TIMER_LOG("[Timer] SetInterval called: app=%s, interval=%dms, ref=%d",
|
||||
app_id.c_str(), interval_ms, callback_ref);
|
||||
|
||||
// Check per-app limit
|
||||
if (m_app_timer_counts[app_id] >= MAX_TIMERS_PER_APP) {
|
||||
TIMER_LOG("[Timer] REJECTED: timer limit exceeded for %s", app_id.c_str());
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, callback_ref);
|
||||
return 0;
|
||||
}
|
||||
@@ -89,6 +100,9 @@ TimerId TimerManager::SetInterval(lua_State* L, const std::string& app_id,
|
||||
m_app_timer_counts[app_id]++;
|
||||
m_app_timer_ids[app_id].insert(timer.id);
|
||||
|
||||
TIMER_LOG("[Timer] Created interval timer id=%llu for %s (total: %zu)",
|
||||
timer.id, app_id.c_str(), m_timers.size());
|
||||
|
||||
return timer.id;
|
||||
}
|
||||
|
||||
@@ -158,9 +172,13 @@ void TimerManager::ClearAppTimers(const std::string& app_id) {
|
||||
|
||||
void TimerManager::FireTimer(Timer& timer) {
|
||||
if (timer.cancelled || timer.callback_ref == LUA_NOREF || !timer.L) {
|
||||
TIMER_LOG("[Timer] FireTimer skipped: cancelled=%d, ref=%d, L=%p",
|
||||
timer.cancelled, timer.callback_ref, timer.L);
|
||||
return;
|
||||
}
|
||||
|
||||
TIMER_LOG("[Timer] Firing timer id=%llu for %s", timer.id, timer.app_id.c_str());
|
||||
|
||||
lua_State* L = timer.L;
|
||||
|
||||
// Get the callback from registry
|
||||
@@ -170,10 +188,15 @@ void TimerManager::FireTimer(Timer& timer) {
|
||||
// Call the callback with protected call
|
||||
int result = lua_pcall(L, 0, 0, 0);
|
||||
if (result != LUA_OK) {
|
||||
// Log error but don't propagate
|
||||
// Log the error
|
||||
const char* err = lua_tostring(L, -1);
|
||||
TIMER_LOG("[Timer] ERROR in callback: %s", err ? err : "(unknown)");
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
TIMER_LOG("[Timer] Callback completed successfully");
|
||||
}
|
||||
} else {
|
||||
TIMER_LOG("[Timer] ERROR: callback ref is not a function!");
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
@@ -209,6 +232,12 @@ int TimerManager::ProcessTimers() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log only when we have timers to fire (to avoid spam)
|
||||
if (!to_fire.empty()) {
|
||||
TIMER_LOG("[Timer] ProcessTimers: %zu ready to fire out of %zu total",
|
||||
to_fire.size(), m_timers.size());
|
||||
}
|
||||
}
|
||||
|
||||
// Fire timers outside the lock to allow callbacks to create new timers
|
||||
|
||||
Reference in New Issue
Block a user