diff --git a/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx b/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx index e2ff102dd..6cfee1416 100644 --- a/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx +++ b/apps/ai-game-creator-shell/src/view/ui-editor/components/preview/PreviewWorkspace.tsx @@ -47,12 +47,21 @@ export function PreviewWorkspace({ useState('editor-overlay'); const [showFrame, setShowFrame] = useState(false); const tree = controller.treeForActiveImage ?? null; + const activeImagePixelWidth = activeImage?.pixel_size[0]; + const activeImagePixelHeight = activeImage?.pixel_size[1]; + const activeImagePixelsPerUnit = activeImage?.pixels_per_unit; const logicalSize = useMemo(() => { - if (!activeImage) return null; - const ppu = activeImage.pixels_per_unit; + if ( + activeImagePixelWidth === undefined || + activeImagePixelHeight === undefined || + activeImagePixelsPerUnit === undefined + ) { + return null; + } + const ppu = activeImagePixelsPerUnit; if (!Number.isFinite(ppu) || ppu <= 0) return null; - const width = activeImage.pixel_size[0] / ppu; - const height = activeImage.pixel_size[1] / ppu; + const width = activeImagePixelWidth / ppu; + const height = activeImagePixelHeight / ppu; if ( !Number.isFinite(width) || !Number.isFinite(height) || @@ -62,7 +71,7 @@ export function PreviewWorkspace({ return null; } return { width, height }; - }, [activeImage]); + }, [activeImagePixelHeight, activeImagePixelsPerUnit, activeImagePixelWidth]); const nodeInteractions = useNodeTransformInteraction({ activeImageId,