{"record":{"id":"a43683fe61717e56","repo":"stride3d/stride","slug":"nameof-newsize-nameof-newsize-x-and-nameof-newsize-y-should","errorCode":null,"errorMessage":"{ nameof(newSize) }.{ nameof(newSize.X) } and { nameof(newSize.Y) } should be greater than 0.","messagePattern":"(.+?)\\.(.+?) and (.+?) should be greater than 0\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Engine/HeightmapUtils.cs","lineNumber":80,"sourceCode":"        public static float ConvertToFloatHeight(float minValue, float maxValue, float value) => MathUtil.InverseLerp(minValue, maxValue, MathUtil.Clamp(value, minValue, maxValue)) * 2 - 1;\n        public static short ConvertToShortHeight(float minValue, float maxValue, float value) => (short)Math.Round(ConvertToFloatHeight(minValue, maxValue, value) * short.MaxValue, MidpointRounding.AwayFromZero);\n        public static byte ConvertToByteHeight(float minValue, float maxValue, float value) => (byte)Math.Round(MathUtil.InverseLerp(minValue, maxValue, MathUtil.Clamp(value, minValue, maxValue)) * byte.MaxValue, MidpointRounding.AwayFromZero);\n\n        public static float[] ConvertToFloatHeights(float[] values, float minValue, float maxValue) => values.Select((v) => ConvertToFloatHeight(minValue, maxValue, v)).ToArray();\n        public static float[] ConvertToFloatHeights(short[] values, short minValue = short.MinValue, short maxValue = short.MaxValue) => values.Select((v) => ConvertToFloatHeight(minValue, maxValue, v)).ToArray();\n        public static float[] ConvertToFloatHeights(byte[] values, byte minValue = byte.MinValue, byte maxValue = byte.MaxValue) => values.Select((v) => ConvertToFloatHeight(minValue, maxValue, v)).ToArray();\n\n        public static short[] ConvertToShortHeights(float[] values, float minValue, float maxValue) => values.Select((v) => ConvertToShortHeight(minValue, maxValue, v)).ToArray();\n        public static short[] ConvertToShortHeights(short[] values, short minValue = short.MinValue, short maxValue = short.MaxValue) => values.Select((v) => ConvertToShortHeight(minValue, maxValue, v)).ToArray();\n        public static short[] ConvertToShortHeights(byte[] values, byte minValue = byte.MinValue, byte maxValue = byte.MaxValue) => values.Select((v) => ConvertToShortHeight(minValue, maxValue, v)).ToArray();\n\n        public static byte[] ConvertToByteHeights(float[] values, float minValue, float maxValue) => values.Select((v) => ConvertToByteHeight(minValue, maxValue, v)).ToArray();\n        public static byte[] ConvertToByteHeights(short[] values, short minValue = short.MinValue, short maxValue = short.MaxValue) => values.Select((v) => ConvertToByteHeight(minValue, maxValue, v)).ToArray();\n\n        public static T[] Resize<T>(T[] pixels, Int2 originalSize, Int2 newSize)\n        {\n            if (originalSize.X < 1 || originalSize.Y < 1) throw new ArgumentException($\"{ nameof(originalSize) }.{ nameof(originalSize.X) } and { nameof(originalSize.Y) } should be greater than 0.\");\n            if (newSize.X < 1 || newSize.Y < 1) throw new ArgumentException($\"{ nameof(newSize) }.{ nameof(newSize.X) } and { nameof(newSize.Y) } should be greater than 0.\");\n\n            if (originalSize.Equals(newSize))\n            {\n                return pixels.ToArray();\n            }\n\n            var originalWidth = originalSize.X;\n            var originalLength = originalSize.Y;\n            var newWidth = newSize.X;\n            var newLength = newSize.Y;\n\n            var scaleX = (newWidth - 1) == 0 ? 0d : ((double)(originalWidth - 1)) / (newWidth - 1);\n            var scaleY = (newLength - 1) == 0 ? 0d : ((double)(originalLength - 1)) / (newLength - 1);\n\n            int GetOriginalIndex(int x, int y) =>\n                (int)Math.Round(y * scaleY, MidpointRounding.AwayFromZero) * originalWidth +\n                (int)Math.Round(x * scaleX, MidpointRounding.AwayFromZero);\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/HeightmapUtils.cs#L62-L98","documentation":"HeightmapUtils.Resize<T> also requires the target newSize to have both dimensions >= 1; resizing to an empty or negative dimension is meaningless and throws ArgumentException immediately after the originalSize check.","triggerScenarios":"Calling Resize with newSize = (0, 0) or (n, 0)/(0, n); computing the target size from a percentage (e.g. 0%) or from a null/empty source that produced 0.","commonSituations":"Configurable level-of-detail value set to 0; dynamic resolution computed from an unloaded source; UI inputs allowing 0 or negative sizes.","solutions":["Clamp newSize to at least (1,1) before calling Resize.","Ensure the LOD/percentage logic cannot produce 0 (Math.Max(1, value)).","Validate user/editor input for the target resolution.","Call with literal known-good dimensions instead of computed ones when possible."],"exampleFix":"// before\nvar resized = HeightmapUtils.Resize(pixels, originalSize, new Int2(0, lodScale));\n// after\nvar newSize = new Int2(Math.Max(1, originalSize.X / lodScale), Math.Max(1, originalSize.Y / lodScale));\nvar resized = HeightmapUtils.Resize(pixels, originalSize, newSize);","handlingStrategy":"validation","validationCode":"newSize = new Int2(Math.Max(1, newSize.X), Math.Max(1, newSize.Y));","typeGuard":"bool CanResize(Int2 from, Int2 to) => from.X >= 1 && from.Y >= 1 && to.X >= 1 && to.Y >= 1;","tryCatchPattern":"try { resized = HeightmapUtils.Resize(pixels, originalSize, newSize); } catch (ArgumentException) { /* clamp size and retry */ }","preventionTips":["Clamp LOD/percentage-driven sizes to >= 1","Validate UI resolution inputs","Guard against empty-source derived sizes"],"tags":["csharp","argument-validation","physics","resize"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}