Description
Aspect ratio is calculated as width / height without checking if height is zero. This could occur with corrupted images or during loading before dimensions are set.
Affected Files
components/canvas-editor.tsx, components/glb-preview.tsx
Current Behavior
// Multiple occurrences without zero-check:
const aspectRatio = croppedImg.width / croppedImg.height // Lines ~653, ~1026, ~1225
const aspectRatio = layer.width / layer.height // Lines ~1605, ~1804
const aspectRatio = croppedThumbnail.width / croppedThumbnail.height // Line ~2868
const aspectRatio = rendererCanvas.width / rendererCanvas.height // Line 293 in glb-preview
Impact
- If height is 0, aspectRatio becomes
Infinity
- Subsequent calculations using aspectRatio will produce invalid dimensions
- Could cause NaN/Infinity to propagate through layer positioning
Suggested Fix
Add defensive checks:
const aspectRatio = height > 0 ? width / height : 1
// Or throw an error for invalid dimensions:
if (height <= 0 || width <= 0) {
console.error('Invalid dimensions:', { width, height })
return
}
Description
Aspect ratio is calculated as
width / heightwithout checking if height is zero. This could occur with corrupted images or during loading before dimensions are set.Affected Files
components/canvas-editor.tsx,components/glb-preview.tsxCurrent Behavior
Impact
InfinitySuggested Fix
Add defensive checks: