diff --git a/CoreTests/NpcNameFinder/Test_NpcNameFinder.cs b/CoreTests/NpcNameFinder/Test_NpcNameFinder.cs index 4d80f79d..0f28ba71 100644 --- a/CoreTests/NpcNameFinder/Test_NpcNameFinder.cs +++ b/CoreTests/NpcNameFinder/Test_NpcNameFinder.cs @@ -35,7 +35,6 @@ internal sealed class Test_NpcNameFinder : IDisposable private readonly IWowScreen screen; - private readonly Stopwatch stopwatch; private readonly StringBuilder stringBuilder; private readonly NpcNameOverlay? npcNameOverlay; @@ -49,7 +48,6 @@ public Test_NpcNameFinder(ILogger logger, WowProcess process, this.logger = logger; this.screen = screen; - stopwatch = new(); stringBuilder = new(); INpcResetEvent npcResetEvent = new NpcResetEvent(); diff --git a/SharedLib/NpcFinder/LineSegmentOperation.cs b/SharedLib/NpcFinder/LineSegmentOperation.cs index 543af6da..45a6dd1d 100644 --- a/SharedLib/NpcFinder/LineSegmentOperation.cs +++ b/SharedLib/NpcFinder/LineSegmentOperation.cs @@ -95,8 +95,10 @@ public readonly void Invoke(int y, Span span) if (i == 0) return; - Interlocked.Add(ref counter.count, i); + int newCount = Interlocked.Add(ref counter.count, i); + if (counter.count + newCount > segments.Length) + return; - span[..i].CopyTo(segments.AsSpan(counter.count, i)); + span[..i].CopyTo(segments.AsSpan(counter.count, newCount)); } } diff --git a/SharedLib/NpcFinder/NpcNameFinder.cs b/SharedLib/NpcFinder/NpcNameFinder.cs index 25d47ad7..0ada638b 100644 --- a/SharedLib/NpcFinder/NpcNameFinder.cs +++ b/SharedLib/NpcFinder/NpcNameFinder.cs @@ -338,7 +338,7 @@ public void Update() resetEvent.Reset(); ReadOnlySpan lineSegments = - PopulateLines(bitmapProvider, Area, colorMatcher, Area, + PopulateLines(colorMatcher, Area, ScaleWidth(MinHeight), ScaleWidth(WidthDiff)); Npcs = DetermineNpcs(lineSegments); @@ -520,11 +520,10 @@ private int YOffset(Rectangle area, Rectangle npc) [SkipLocalsInit] private ReadOnlySpan PopulateLines( - IScreenImageProvider provider, Rectangle rect, Func colorMatcher, Rectangle area, float minLength, float lengthDiff) { - const int RESOLUTION = 32; + const int RESOLUTION = 16; int rowSize = (area.Right - area.Left) / RESOLUTION; int height = (area.Bottom - area.Top) / RESOLUTION; int totalSize = rowSize * height; @@ -553,7 +552,7 @@ private ReadOnlySpan PopulateLines( in operation); pooler.Return(segments); - return new(segments, 0, counter.count); + return new(segments, 0, Math.Min(segments.Length, counter.count)); } public Point ToScreenCoordinates()