diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index 9f639774..e5eebbfc 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -511,6 +511,7 @@ namespace NewHorizons.Builder.Props if (useAtlasCache && cacheExists) { + NHLogger.LogVerbose($"The atlas cache for slide reel containing [{slides.FirstOrDefault(x => !string.IsNullOrEmpty(x.imagePath))?.imagePath}] is {atlasKey}"); // Load the atlas texture used to draw onto the physical slide reel object atlasImageLoader.PathsToLoad.Add((0, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, ATLAS_SLIDE_CACHE_FOLDER, $"{atlasKey}.png"))); } @@ -523,7 +524,12 @@ namespace NewHorizons.Builder.Props if (string.IsNullOrEmpty(slideInfo.imagePath)) { - imageLoader.imageLoadedEvent?.Invoke(Texture2D.blackTexture, i, null); + // Delay at least one frame to let things subscribe to the event before it fires + int index = i; + Delay.FireOnNextUpdate(() => + { + imageLoader.imageLoadedEvent?.Invoke(ImageUtilities.MakeSolidColorTexture(256, 256, Color.black), index, null); + }); } else { diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 939bcde2..c6ef49da 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -425,6 +425,9 @@ namespace NewHorizons.Utility.Files } public static Texture2D MakeSolidColorTexture(int width, int height, Color color) { + var key = $"{color} {width} {height}"; + if (_textureCache.TryGetValue(key, out var existingTexture)) return (Texture2D)existingTexture; + var pixels = new Color[width * height]; for (int i = 0; i < pixels.Length; i++) @@ -435,6 +438,9 @@ namespace NewHorizons.Utility.Files var newTexture = new Texture2D(width, height); newTexture.SetPixels(pixels); newTexture.Apply(); + + _textureCache.Add(key, newTexture); + return newTexture; }