From e67ddc7fe6d2a109a35f43baf62ff5cc77c3f53b Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 25 Jul 2022 21:25:36 -0400 Subject: [PATCH] Cap the number of points we generate when doing scatter to not run out of memory --- NewHorizons/Builder/Props/ScatterBuilder.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index dc2740cf..c949d026 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -20,7 +20,12 @@ namespace NewHorizons.Builder.Props var heightMap = config.HeightMap; var area = 4f * Mathf.PI * radius * radius; - var points = RandomUtility.FibonacciSphere((int)(area * 10)); + + // To not use more than 0.5GB of RAM while doing this + // Works up to planets with 575 radius before capping + var numPoints = Math.Min((int)(area * 10), 41666666); + + var points = RandomUtility.FibonacciSphere(numPoints); Texture2D heightMapTexture = null; if (heightMap != null)