From 77a2a5039f155e875ff1f9043f4bb9f8212eb07d Mon Sep 17 00:00:00 2001 From: AI Bot Date: Thu, 30 Jul 2026 17:00:05 +0530 Subject: [PATCH] Fix UV canvas CORS tainting preventing image export --- src/components/UVEditor.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/UVEditor.tsx b/src/components/UVEditor.tsx index 6a36444..4314255 100644 --- a/src/components/UVEditor.tsx +++ b/src/components/UVEditor.tsx @@ -52,6 +52,7 @@ export function UVEditor({ onClose, onSave, targetObject, loadedModel, sceneObje const init: Layer[] = saved.map((l: any) => ({ ...l })); init.forEach(layer => { const img = new Image(); + img.crossOrigin = "anonymous"; img.onload = () => { layer.img = img; n++; if (n === init.length) setLayers([...init]); }; img.src = layer.url; }); @@ -59,6 +60,7 @@ export function UVEditor({ onClose, onSave, targetObject, loadedModel, sceneObje // If no saved layers but there's a base map texture, load it as the initial layer const url = targetObject.materialProps.map; const img = new Image(); + img.crossOrigin = "anonymous"; img.onload = () => { // Automatically scale the image so it fits the 1024x1024 canvas exactly const scaleX = CANVAS_SIZE / img.width; @@ -104,7 +106,12 @@ export function UVEditor({ onClose, onSave, targetObject, loadedModel, sceneObje ctx.drawImage(layer.img, sx, sy, sw, sh, -sw / 2, -sh / 2, sw, sh); ctx.restore(); }); - return c.toDataURL(transparent ? 'image/png' : 'image/jpeg'); + try { + return c.toDataURL(transparent ? 'image/png' : 'image/jpeg'); + } catch (e) { + console.error("Canvas render error (likely CORS taint):", e); + return ""; + } }, []); useEffect(() => {