From 83958d9f5974f221a56ef668137e515792314373 Mon Sep 17 00:00:00 2001 From: EmoSaru Date: Thu, 14 May 2026 01:03:36 -0700 Subject: [PATCH] Fix autotracker period throttle, Dirty flag, and Lua debugger exception pause - MemorySegment.ShouldUpdate: fix inverted comparison that caused updates to spam every poll tick until the period elapsed, then stop permanently - LuaMemorySegment: clear Dirty flag when the Lua callback returns a truthy value so normal period-based throttling resumes after each successful update - LuaDebuggee.EnterExceptionPause: bail early when no DAP session is attached so Lua errors don't trigger debugger pause logic at runtime - Make MemorySegment abstract (OnSegmentDataUpdated was already abstract) Co-Authored-By: Claude Sonnet 4.6 --- EmoTracker.Data/AutoTracking/LuaMemorySegment.cs | 9 ++++++--- EmoTracker.Data/AutoTracking/MemorySegment.cs | 6 ++---- EmoTracker.Data/Debugging/LuaDebuggee.cs | 2 ++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/EmoTracker.Data/AutoTracking/LuaMemorySegment.cs b/EmoTracker.Data/AutoTracking/LuaMemorySegment.cs index 0aa0254..28e77d0 100644 --- a/EmoTracker.Data/AutoTracking/LuaMemorySegment.cs +++ b/EmoTracker.Data/AutoTracking/LuaMemorySegment.cs @@ -58,8 +58,6 @@ public LuaMemorySegment() : base() protected override void OnSegmentDataUpdated() { - base.OnSegmentDataUpdated(); - var state = this.OwnerState as Sessions.TrackerState; if (state == null) return; var scripts = state.Scripts; @@ -76,10 +74,15 @@ protected override void OnSegmentDataUpdated() { try { + object[] result; using (new LocationDatabase.SuspendRefreshScope(state.Locations)) { - scripts.SafeCall(callback, this); + result = scripts.SafeCall(callback, this); } + bool succeeded = result != null && result.Length > 0 + && result[0] != null && !(result[0] is bool b && !b); + if (succeeded) + Dirty = false; } catch (Exception ex) { diff --git a/EmoTracker.Data/AutoTracking/MemorySegment.cs b/EmoTracker.Data/AutoTracking/MemorySegment.cs index b1a7b0c..5ac3bf7 100644 --- a/EmoTracker.Data/AutoTracking/MemorySegment.cs +++ b/EmoTracker.Data/AutoTracking/MemorySegment.cs @@ -33,7 +33,7 @@ namespace EmoTracker.Data.AutoTracking /// data (override ). /// /// - public class MemorySegment : ModelTypeBase, IMemorySegment, IUpdateWithConnector, IDisposable + public abstract class MemorySegment : ModelTypeBase, IMemorySegment, IUpdateWithConnector, IDisposable { #region -- Global Event Hooks -- @@ -339,9 +339,7 @@ public MemoryUpdateResult UpdateWithConnector(IAutoTrackingProvider provider, Pa /// overrides to dispatch onto the UI thread and SafeCall the /// pack-supplied LuaFunction callback. /// - protected virtual void OnSegmentDataUpdated() - { - } + protected abstract void OnSegmentDataUpdated(); public override void Dispose() { diff --git a/EmoTracker.Data/Debugging/LuaDebuggee.cs b/EmoTracker.Data/Debugging/LuaDebuggee.cs index db2eb6b..5557e53 100644 --- a/EmoTracker.Data/Debugging/LuaDebuggee.cs +++ b/EmoTracker.Data/Debugging/LuaDebuggee.cs @@ -667,6 +667,8 @@ void ServeRequest(DebugRequest req) internal void EnterExceptionPause(string errMessage, string traceback) { + if (!(LuaDebugServer.Instance?.HasActiveSession ?? false)) return; + // Always log so we can confirm the upcall actually // reached us — the Lua-side handler's pcall around the // upcall would otherwise silently swallow any throw.