Fix hot reload init ordering: move after core objects are created

InitializeForHotReload() was called at the top of Startup() before
_killTracker, _chatEventRouter, and _inventoryMonitor were created,
causing NullReferenceException. Move the hot reload block to after
all core objects are initialized.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
erik 2026-02-27 14:55:26 +00:00
parent 1fff36e3f7
commit 361c2012da
2 changed files with 18 additions and 23 deletions

View file

@ -154,30 +154,10 @@ namespace MosswartMassacre
MyHost = null; MyHost = null;
} }
// Check if this is a hot reload // Check if this is a hot reload (flag for post-init handling)
var isCharacterLoaded = CoreManager.Current.CharacterFilter.LoginStatus == 3; var isCharacterLoaded = CoreManager.Current.CharacterFilter.LoginStatus == 3;
if (IsHotReload || isCharacterLoaded) var needsHotReload = IsHotReload || isCharacterLoaded;
{
// Hot reload detected - reinitialize connections and state
WriteToChat("[INFO] Hot reload detected - reinitializing plugin");
// Reload settings if character is already logged in
if (isCharacterLoaded)
{
try
{
WriteToChat("Hot reload - reinitializing character-dependent systems");
// Don't call LoginComplete - create hot reload specific initialization
InitializeForHotReload();
WriteToChat("[INFO] Hot reload initialization complete");
}
catch (Exception ex)
{
WriteToChat($"[ERROR] Hot reload initialization failed: {ex.Message}");
}
}
}
// Initialize kill tracker (owns the 1-sec stats timer) // Initialize kill tracker (owns the 1-sec stats timer)
_killTracker = new KillTracker( _killTracker = new KillTracker(
this, this,
@ -260,6 +240,21 @@ namespace MosswartMassacre
// Note: DECAL Harmony patches will be initialized in LoginComplete event // Note: DECAL Harmony patches will be initialized in LoginComplete event
// where the chat system is available for error messages // where the chat system is available for error messages
// Hot reload: run after all core objects are initialized
if (needsHotReload && isCharacterLoaded)
{
try
{
WriteToChat("[INFO] Hot reload detected - reinitializing plugin");
InitializeForHotReload();
WriteToChat("[INFO] Hot reload initialization complete");
}
catch (Exception ex)
{
WriteToChat($"[ERROR] Hot reload initialization failed: {ex.Message}");
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {