diff --git a/HarmonySrc/GhostTraderPatch.cs b/HarmonySrc/GhostTraderPatch.cs index df56b25..28e285f 100644 --- a/HarmonySrc/GhostTraderPatch.cs +++ b/HarmonySrc/GhostTraderPatch.cs @@ -259,6 +259,15 @@ namespace NecromancerTome public static void OnWorldShuttingDown(ref ModEvents.SWorldShuttingDownData _data) { Ghosted.Clear(); + // Серые копии - свои текстуры мода, Clear их не выгружает: без Destroy каждая + // перезагрузка мира оставляла их в видеопамяти. + foreach (Texture2D grey in GreyTextures.Values) + { + if (grey != null) + { + Object.Destroy(grey); + } + } GreyTextures.Clear(); TintedMaterials.Clear(); Converted.Clear(); @@ -1079,13 +1088,20 @@ namespace NecromancerTome RenderTexture previous = RenderTexture.active; try { - rt = RenderTexture.GetTemporary(_source.width, _source.height, 0, + // Как в CorpseLootPatch.Tint: уменьшение самим Blit до MaxTintSize, стороны + // кратны четырём для Compress. Раньше копия была 4096x4096 RGBA32 - 64 МБ + // видеопамяти на текстуру плюс столько же в оперативной (тормоза на стриме 28.09). + float scale = Mathf.Min(1f, (float)CorpseLoot.MaxTintSize / Mathf.Max(_source.width, _source.height)); + int width = Mathf.Max(4, (int)(_source.width * scale) / 4 * 4); + int height = Mathf.Max(4, (int)(_source.height * scale) / 4 * 4); + + rt = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); Graphics.Blit(_source, rt); RenderTexture.active = rt; - grey = new Texture2D(_source.width, _source.height, TextureFormat.RGBA32, false); - grey.ReadPixels(new Rect(0f, 0f, _source.width, _source.height), 0, 0); + grey = new Texture2D(width, height, TextureFormat.RGBA32, false); + grey.ReadPixels(new Rect(0f, 0f, width, height), 0, 0); Color32[] pixels = grey.GetPixels32(); for (int i = 0; i < pixels.Length; i++) @@ -1098,11 +1114,16 @@ namespace NecromancerTome pixels[i] = p; } grey.SetPixels32(pixels); - grey.Apply(false, false); + grey.Compress(false); + grey.Apply(false, true); } catch (System.Exception e) { Debug.LogError("[NecromancerTome] GhostTraderPatch: could not desaturate '" + _source.name + "': " + e.Message); + if (grey != null) + { + Object.Destroy(grey); + } grey = null; } finally diff --git a/NecromancerHarmony.dll b/NecromancerHarmony.dll index 53d166b..bf722c2 100644 Binary files a/NecromancerHarmony.dll and b/NecromancerHarmony.dll differ diff --git a/NecromancerHarmony.pdb b/NecromancerHarmony.pdb index fa2d3a9..e6c9c68 100644 Binary files a/NecromancerHarmony.pdb and b/NecromancerHarmony.pdb differ