{"record":{"id":"6682531700e21cc2","repo":"stride3d/stride","slug":"nameof-originalsize-nameof-originalsize-x-and-nameof","errorCode":null,"errorMessage":"{ nameof(originalSize) }.{ nameof(originalSize.X) } and { nameof(originalSize.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":79,"sourceCode":"\n        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);","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/HeightmapUtils.cs#L61-L97","documentation":"HeightmapUtils.Resize<T> resamples a heightmap pixel buffer to a new size, and both originalSize dimensions must be at least 1. Passing an empty/default Int2 (or any dimension < 1) for originalSize throws ArgumentException, as there is no source data to resample.","triggerScenarios":"Calling Resize with originalSize = default(Int2) i.e. (0,0); a heightmap whose Size was never initialized; passing width or height 0/negative from computed values.","commonSituations":"Resizing before loading/generating heightmap data; a failed import leaving Size at default; off-by-one or multiplication producing 0 dimensions.","solutions":["Ensure the source heightmap has data and Size >= (1,1) before calling Resize.","Guard the call: if (originalSize.X < 1 || originalSize.Y < 1) handle before resizing.","Initialize the heightmap Size when creating it programmatically.","Fix the computation that yields the original size (image dimensions, array length mapping)."],"exampleFix":"// before\nvar resized = HeightmapUtils.Resize(pixels, new Int2(0, 0), newSize);\n// after\nif (heightmap.Size.X > 0 && heightmap.Size.Y > 0)\n    var resized = HeightmapUtils.Resize(pixels, heightmap.Size, newSize);","handlingStrategy":"validation","validationCode":"if (originalSize.X < 1 || originalSize.Y < 1) throw/return;","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) { /* log and skip resize */ }","preventionTips":["Only resize loaded heightmaps","Verify Size after import","Check dimension math for 0 results"],"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"}