Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions EmoTracker.Data/AutoTracking/LuaMemorySegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ protected override void OnSegmentDataUpdated()
if (state == null) return;
var scripts = state.Scripts;
if (scripts == null) return;
var callback = mCallback;
if (callback == null) return;
if (mCallback == null) return;

// Memory polling fires on a worker thread. The callback may
// mutate items / locations, both of which expect UI-thread
Expand All @@ -74,10 +73,19 @@ protected override void OnSegmentDataUpdated()
{
try
{
// Re-read mCallback at execution time. A pack reload
// between the queue-time check above and now would have
// torn down our Lua state and called Dispose() on this
// segment (which nulls mCallback). Invoking SafeCall
// with a LuaFunction whose underlying state is closed
// hangs the UI thread inside NLua — issue #93.
var liveCallback = mCallback;
if (liveCallback == null) return;
if (!scripts.IsLuaLoaded) return;
object[] result;
using (new LocationDatabase.SuspendRefreshScope(state.Locations))
{
result = scripts.SafeCall(callback, this);
result = scripts.SafeCall(liveCallback, this);
}
bool succeeded = result != null && result.Length > 0
&& result[0] != null && !(result[0] is bool b && !b);
Expand Down
37 changes: 19 additions & 18 deletions EmoTracker/Extensions/AutoTracker/AutoTrackerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,28 @@ void OnAnyPackageLoadStarting(object sender, EmoTracker.Data.Sessions.PackageLoa
if (!ReferenceEquals(e.Target, mState)) return;

// The state's Lua interpreter is about to be Reset() — close +
// re-open. Drop our memory segments now so we don't carry
// callbacks that reference the soon-to-be-closed interpreter.
// StopAutoTracking first to drain any in-flight poll cleanly;
// the active provider connection itself is preserved (the user
// chose to stay connected across reloads), but the watch list
// is rebuilt by the new init.lua's AddMemoryWatch calls.
// re-open. Fully stop autotracking before the reload: keeping
// the connection alive across reload left the extension stuck
// in an "active/running" state that didn't actually refresh
// (the new pack's init.lua re-registers watches against the
// new Lua state, but the throttle / dirty bookkeeping carried
// from the old run prevents updates from landing until the
// user manually stops and restarts).
//
// Without this hook, the next memory poll after reload+
// reconnect invokes SafeCall on a LuaFunction whose underlying
// Lua state is closed, which hangs the UI thread inside NLua.
bool wasConnected = ActiveProvider != null;
var preservedProvider = SelectedProvider;

// Drain in-flight + dispose stale segments. Note Clear() also
// clears the pending update queue.
// StopAutoTracking drains any in-flight poll, disconnects the
// active provider, and fires the AutoTrackerStopped callback.
// Clear() then drops the pending-update queue. The user will
// re-Start once the pack finishes loading.
StopAutoTracking();
Clear();

// Restore the connection target so the user doesn't have to
// re-pick it after init.lua repopulates the watch list.
if (preservedProvider != null)
SelectedProvider = preservedProvider;
// Surface the now-stopped state to bindings; OnAnyPackageLoad-
// Complete will re-emit these too once new segments / timers
// are registered, but raise them here so the status bar
// reflects "not running" during the reload window rather than
// showing stale running state.
NotifyPropertyChanged(nameof(Active));
NotifyPropertyChanged(nameof(StatusBarControl));
}

void OnAnyPackageLoadComplete(object sender, EmoTracker.Data.Sessions.PackageLoader.PackageLoadEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion EmoTracker/Providers/NWA/NwaDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static INwaAddressMap CreatePlatformAddressMap(GamePlatform platform)
/// </summary>
async Task<byte[]> ReadRawDomainAsync(string domain, ulong offset, int length)
{
string command = $"CORE_READ {domain} ${offset:X};${length:X}";
string command = $"CORE_READ {domain};${offset:X};${length:X}";
byte[] data = await SendReadCommandAsync(command).ConfigureAwait(false);
return data ?? Array.Empty<byte>();
}
Expand Down
Loading