diff --git a/src/HexManiac.Core/Models/Runs/ArrayRun.cs b/src/HexManiac.Core/Models/Runs/ArrayRun.cs index acfa7d10..bad674e7 100644 --- a/src/HexManiac.Core/Models/Runs/ArrayRun.cs +++ b/src/HexManiac.Core/Models/Runs/ArrayRun.cs @@ -155,6 +155,8 @@ namespace HavenSoft.HexManiac.Core.Models.Runs { cachedOptions = results; return results; } + + public void ClearCache() { cachedOptions = null; } } public class ArrayOffset { @@ -580,6 +582,21 @@ namespace HavenSoft.HexManiac.Core.Models.Runs { return new ArrayRun(owner, FormatString, LengthFromAnchor, newStart, ElementCount, ElementContent, PointerSources, PointerSourcesForInnerElements); } + /// + /// For performance reasons, arrays store copies of strings from arrays that they're based on. + /// For example, if the array contains an enum of types, that enum segment will store the list of types. + /// For example, if the array is the same length as the pokemon array, the array will store the list of pokemon names. + /// Calling this method will clear those caches and force re-evaluation. + /// + public void ClearCache() { + cachedElementNames = null; + foreach (var child in ElementContent) { + if (child is ArrayRunEnumSegment enumSegment) { + enumSegment.ClearCache(); + } + } + } + public override IFormattedRun RemoveSource(int source) { if (!SupportsPointersToElements) return base.RemoveSource(source); var newPointerSources = PointerSources.Where(item => item != source).ToList(); diff --git a/src/HexManiac.Core/ViewModels/ViewPort.cs b/src/HexManiac.Core/ViewModels/ViewPort.cs index 68029283..f151cb54 100644 --- a/src/HexManiac.Core/ViewModels/ViewPort.cs +++ b/src/HexManiac.Core/ViewModels/ViewPort.cs @@ -1281,7 +1281,10 @@ namespace HavenSoft.HexManiac.Core.ViewModels { for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { var index = scroll.ViewPointToDataIndex(new Point(x, y)); - if (run == null || index >= run.Start + run.Length) run = Model.GetNextRun(index) ?? new NoInfoRun(Model.Count); + if (run == null || index >= run.Start + run.Length) { + run = Model.GetNextRun(index) ?? new NoInfoRun(Model.Count); + if (run is ArrayRun array) array.ClearCache(); + } if (index < 0 || index >= Model.Count) { currentView[x, y] = HexElement.Undefined; } else if (index >= run.Start) {