stride3d/stride · error · ArgumentException
. and should be greater than 0.
Error message
{ nameof(originalSize) }.{ nameof(originalSize.X) } and { nameof(originalSize.Y) } should be greater than 0. What it means
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.
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).
Example fix
// before
var resized = HeightmapUtils.Resize(pixels, new Int2(0, 0), newSize);
// after
if (heightmap.Size.X > 0 && heightmap.Size.Y > 0)
var resized = HeightmapUtils.Resize(pixels, heightmap.Size, newSize); Defensive patterns
Strategy: validation
Validate before calling
if (originalSize.X < 1 || originalSize.Y < 1) throw/return;
Type guard
bool CanResize(Int2 from, Int2 to) => from.X >= 1 && from.Y >= 1 && to.X >= 1 && to.Y >= 1;
Try / catch
try { resized = HeightmapUtils.Resize(pixels, originalSize, newSize); } catch (ArgumentException) { /* log and skip resize */ } Prevention
- Only resize loaded heightmaps
- Verify Size after import
- Check dimension math for 0 results
When it happens
Trigger: 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.
Common situations: Resizing before loading/generating heightmap data; a failed import leaving Size at default; off-by-one or multiplication producing 0 dimensions.
Related errors
- . and should be greater than 0.
- Can't handle included both of positive and negative in type.
- is too short.
- . should be greater than .
- is 0.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/6682531700e21cc2.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Physics/Engine/HeightmapUtils.cs:79
public static float ConvertToFloatHeight(float minValue, float maxValue, float value) => MathUtil.InverseLerp(minValue, maxValue, MathUtil.Clamp(value, minValue, maxValue)) * 2 - 1;
public static short ConvertToShortHeight(float minValue, float maxValue, float value) => (short)Math.Round(ConvertToFloatHeight(minValue, maxValue, value) * short.MaxValue, MidpointRounding.AwayFromZero);
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);
public static float[] ConvertToFloatHeights(float[] values, float minValue, float maxValue) => values.Select((v) => ConvertToFloatHeight(minValue, maxValue, v)).ToArray();
public static float[] ConvertToFloatHeights(short[] values, short minValue = short.MinValue, short maxValue = short.MaxValue) => values.Select((v) => ConvertToFloatHeight(minValue, maxValue, v)).ToArray();
public static float[] ConvertToFloatHeights(byte[] values, byte minValue = byte.MinValue, byte maxValue = byte.MaxValue) => values.Select((v) => ConvertToFloatHeight(minValue, maxValue, v)).ToArray();
public static short[] ConvertToShortHeights(float[] values, float minValue, float maxValue) => values.Select((v) => ConvertToShortHeight(minValue, maxValue, v)).ToArray();
public static short[] ConvertToShortHeights(short[] values, short minValue = short.MinValue, short maxValue = short.MaxValue) => values.Select((v) => ConvertToShortHeight(minValue, maxValue, v)).ToArray();
public static short[] ConvertToShortHeights(byte[] values, byte minValue = byte.MinValue, byte maxValue = byte.MaxValue) => values.Select((v) => ConvertToShortHeight(minValue, maxValue, v)).ToArray();
public static byte[] ConvertToByteHeights(float[] values, float minValue, float maxValue) => values.Select((v) => ConvertToByteHeight(minValue, maxValue, v)).ToArray();
public static byte[] ConvertToByteHeights(short[] values, short minValue = short.MinValue, short maxValue = short.MaxValue) => values.Select((v) => ConvertToByteHeight(minValue, maxValue, v)).ToArray();
public static T[] Resize<T>(T[] pixels, Int2 originalSize, Int2 newSize)
{
if (originalSize.X < 1 || originalSize.Y < 1) throw new ArgumentException($"{ nameof(originalSize) }.{ nameof(originalSize.X) } and { nameof(originalSize.Y) } should be greater than 0.");
if (newSize.X < 1 || newSize.Y < 1) throw new ArgumentException($"{ nameof(newSize) }.{ nameof(newSize.X) } and { nameof(newSize.Y) } should be greater than 0.");
if (originalSize.Equals(newSize))
{
return pixels.ToArray();
}
var originalWidth = originalSize.X;
var originalLength = originalSize.Y;
var newWidth = newSize.X;
var newLength = newSize.Y;
var scaleX = (newWidth - 1) == 0 ? 0d : ((double)(originalWidth - 1)) / (newWidth - 1);
var scaleY = (newLength - 1) == 0 ? 0d : ((double)(originalLength - 1)) / (newLength - 1);
int GetOriginalIndex(int x, int y) =>
(int)Math.Round(y * scaleY, MidpointRounding.AwayFromZero) * originalWidth +
(int)Math.Round(x * scaleX, MidpointRounding.AwayFromZero);View on GitHub (pinned to 96fad776d2)