diff --git a/Libraries/SEModAPIExtensions.dll b/Libraries/SEModAPIExtensions.dll index e8276d4..66ec0a8 100644 Binary files a/Libraries/SEModAPIExtensions.dll and b/Libraries/SEModAPIExtensions.dll differ diff --git a/Libraries/SEModAPIInternal.dll b/Libraries/SEModAPIInternal.dll index 02ce8a8..bb492f9 100644 Binary files a/Libraries/SEModAPIInternal.dll and b/Libraries/SEModAPIInternal.dll differ diff --git a/WarpDrivePlugin/Core.cs b/WarpDrivePlugin/Core.cs index 069f5b6..9a657e4 100644 --- a/WarpDrivePlugin/Core.cs +++ b/WarpDrivePlugin/Core.cs @@ -228,16 +228,27 @@ public override void Update() TimeSpan timeSinceLastFullScan = DateTime.Now - m_lastFullScan; if (timeSinceLastFullScan.TotalMilliseconds > 30000) { - LogManager.APILog.WriteLine("Scanning all entities for valid warp drives ..."); + m_lastFullScan = DateTime.Now; + LogManager.APILog.WriteLine("WarpDrivePlugin - Initializing full scan ..."); //Run cleanup CleanUpEngineMap(); - //Run full scan - FullScan(); + //Queue up a full scan + Action action = FullScan; + SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action); } } + public override void Shutdown() + { + foreach (WarpEngine warpEngine in m_warpEngineMap.Values) + { + warpEngine.Dispose(); + } + m_warpEngineMap.Clear(); + } + public void OnCubeBlockCreated(CubeBlockEntity cubeBlock) { CubeGridEntity cubeGrid = cubeBlock.Parent; @@ -267,31 +278,43 @@ public void OnCubeBlockCreated(CubeBlockEntity cubeBlock) public void OnCubeBlockDeleted(CubeBlockEntity cubeBlock) { - if (cubeBlock.Parent.GridSizeEnum != MyCubeSize.Large) + if (cubeBlock == null) return; CubeGridEntity cubeGrid = cubeBlock.Parent; - if (cubeGrid == null || !m_warpEngineMap.ContainsKey(cubeGrid)) + //Check for invalid cube grid + if (cubeGrid == null) + return; + if (cubeGrid.GridSizeEnum != MyCubeSize.Large) return; + if (!m_warpEngineMap.ContainsKey(cubeGrid)) + return; + if (cubeGrid.IsDisposed) + { + RemoveWarpEngine(cubeGrid); + return; + } + //Check for invalid warp engine WarpEngine warpEngine = m_warpEngineMap[cubeGrid]; - bool shouldRemove = false; + if (warpEngine == null) + return; + if (warpEngine.IsDisposed) + { + RemoveWarpEngine(cubeGrid); + return; + } + + //Check for invalid blocks foreach (CubeBlockEntity block in warpEngine.Blocks) { if (block == null || block == cubeBlock || block.IsDisposed) { - shouldRemove = true; + RemoveWarpEngine(cubeGrid); break; } } - if (cubeGrid.IsDisposed) - shouldRemove = true; - - if (shouldRemove) - { - RemoveWarpEngine(cubeGrid); - } } #endregion @@ -339,18 +362,26 @@ protected bool CheckEngineForRemoval(WarpEngine engine) protected void CleanUpEngineMap() { - foreach (WarpEngine engine in m_warpEngineMap.Values) + try { - if (CheckEngineForRemoval(engine)) + foreach (WarpEngine engine in m_warpEngineMap.Values) { - RemoveWarpEngine(engine.Parent); + if (CheckEngineForRemoval(engine)) + { + RemoveWarpEngine(engine.Parent); + } } } + catch (Exception ex) + { + LogManager.GameLog.WriteLine(ex); + } } protected void FullScan() { - m_lastFullScan = DateTime.Now; + LogManager.APILog.WriteLine("WarpDrivePlugin - Scanning all entities for valid warp drives ..."); + foreach (BaseEntity entity in SectorObjectManager.Instance.GetTypedInternalData()) { try diff --git a/WarpDrivePlugin/Properties/AssemblyInfo.cs b/WarpDrivePlugin/Properties/AssemblyInfo.cs index ff3e76f..39ca9c5 100644 --- a/WarpDrivePlugin/Properties/AssemblyInfo.cs +++ b/WarpDrivePlugin/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("0.1.4.0")] -[assembly: AssemblyFileVersion("0.1.4.0")] +[assembly: AssemblyVersion("0.1.4.1")] +[assembly: AssemblyFileVersion("0.1.4.1")]