Призрачные торговцы: серые текстуры 1024 и сжатые, выгрузка из ОЗУ

Серые копии были 4096x4096 RGBA32 без сжатия (64 МБ видеопамяти каждая плюс CPU-копия) - на стриме 28.09 это добавило к переполнению 8 ГБ видеокарты. Теперь как в CorpseLoot: уменьшение до MaxTintSize, Compress, Apply(makeNoLongerReadable). При выходе из мира копии уничтожаются, а не просто забываются.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
AlexCube
2026-09-28 20:52:36 +03:00
co-authored by Claude Opus 5.5
parent 4b54b48d68
commit 048307eda8
3 changed files with 25 additions and 4 deletions
+25 -4
View File
@@ -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
Binary file not shown.
Binary file not shown.