From b69b613984e6e5895c21ca234851275bb908483a Mon Sep 17 00:00:00 2001 From: chrg6 Date: Sun, 8 Nov 2026 09:22:03 -0500 Subject: [PATCH] Fix small settings and overlay edge cases. - An empty NX2NAVI_SPIN or NX2NAVI_VRAM_HEADROOM in the environment stopped the game: both read the key with cfg_bool, and an empty value falls back to the settings table, where these keys have no row. Empty now means unset. - find_ini checked for 10 bytes after the exe folder's separator where "nx2navi.ini" and its NUL take 12, so an exe path just under 1024 bytes wrote two bytes past the buffer. - The performance overlay read the clock before taking the lock, so a frame pushed in between was newer than "now", the unsigned age wrapped and the overlay showed 0 fps for that refresh. Co-Authored-By: Claude Opus 5.5 --- runtime/cfg.c | 2 +- runtime/kernel.c | 4 +++- runtime/perfmon.c | 4 +++- runtime/vk_headroom.c | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/runtime/cfg.c b/runtime/cfg.c index 8b3e81e4..4601f3d3 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -706,7 +706,7 @@ static int find_ini(void) { if (!plat_exe_path(path, sizeof path)) return 0; char *cut = plat_last_sep(path); if (!cut) cut = strrchr(path, '/'); - if (!cut || cut + 10 >= path + sizeof path) return 0; + if (!cut || cut + 12 >= path + sizeof path) return 0; // room for "nx2navi.ini" and its NUL after the separator strcpy(cut + 1, "nx2navi.ini"); snprintf(ini_path, sizeof ini_path, "%s", path); return 1; diff --git a/runtime/kernel.c b/runtime/kernel.c index 8c4d5a63..1adb54dc 100644 --- a/runtime/kernel.c +++ b/runtime/kernel.c @@ -1098,7 +1098,9 @@ void rt_spin_gate(Cpu *c, uint64_t head) { if (g_spin_on < 0) { const char *e = cfg_get("NX2NAVI_SPIN_HANDOFF_US"); g_spin_handoff_ns = (uint64_t)(e && *e ? atoll(e) : 50) * 1000; - g_spin_on = !(cfg_get("NX2NAVI_SPIN") && !cfg_bool("NX2NAVI_SPIN")); + // an empty value is unset: cfg_bool of a key without a settings row would stop the game on it + const char *spin = cfg_get("NX2NAVI_SPIN"); + g_spin_on = !(spin && *spin && !cfg_bool("NX2NAVI_SPIN")); } t->sp_n++; t->sp_site = head; diff --git a/runtime/perfmon.c b/runtime/perfmon.c index d320ebcd..9ae8a431 100644 --- a/runtime/perfmon.c +++ b/runtime/perfmon.c @@ -380,8 +380,10 @@ void perfmon_mode(int mode) { } void perfmon_snapshot(PerfStats *out) { - uint64_t now = plat_now_ns(); + // the time under the lock: a frame pushed between the two would be newer than now, and now - at wrapping would + // end the frame window at once (0 fps on the overlay) plat_mutex_lock(&g_lock); + uint64_t now = plat_now_ns(); frames_summary(&g_stats, now); counters_summary(now); *out = g_stats; diff --git a/runtime/vk_headroom.c b/runtime/vk_headroom.c index 7809c640..6067c6ae 100644 --- a/runtime/vk_headroom.c +++ b/runtime/vk_headroom.c @@ -49,7 +49,8 @@ static void VKAPI_PTR on_allocate(VmaAllocator a, uint32_t type, VkDeviceMemory const VmaDeviceMemoryCallbacks *vk_headroom_callbacks(void) { static const VmaDeviceMemoryCallbacks cb = {.pfnAllocate = on_allocate}; - H.on = !cfg_get("NX2NAVI_VRAM_HEADROOM") || cfg_bool("NX2NAVI_VRAM_HEADROOM"); + const char *v = cfg_get("NX2NAVI_VRAM_HEADROOM"); // empty is unset: the key has no settings row for cfg_bool + H.on = !v || !*v || cfg_bool("NX2NAVI_VRAM_HEADROOM"); return H.on ? &cb : NULL; }