Skip to content

Commit 2a73fb6

Browse files
committed
🐛 修复部分旧版json导入时报错
1 parent e540a32 commit 2a73fb6

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

app/src/core/render/canvas2d/basicRenderer/textRenderer.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ export class TextRenderer {
5252
return nearestBitmap;
5353
}
5454

55-
private buildCache(text: string, size: number, color: Color) {
55+
private buildCache(text: string, size: number, color: Color): CanvasImageSource {
5656
const textSize = getTextSize(text, size);
5757
// 这里用OffscreenCanvas而不是document.createElement("canvas")
5858
// 因为OffscreenCanvas有神秘优化,后续也方便移植到Worker中渲染
59+
if (textSize.x <= 1 || textSize.y <= 1) {
60+
// 如果文本大小为0,直接返回一个透明图片
61+
return new Image();
62+
}
5963
const canvas = new OffscreenCanvas(textSize.x, textSize.y * 1.5);
6064
const ctx = canvas.getContext("2d")!;
6165
// 如果这里开了抗锯齿,并且外层的canvas也开了抗锯齿,会导致文字模糊
@@ -65,10 +69,12 @@ export class TextRenderer {
6569
ctx.font = `${size}px normal ${FONT}`;
6670
ctx.fillStyle = color.toString();
6771
ctx.fillText(text, 0, size / 2);
68-
createImageBitmap(canvas).then((bmp) => {
69-
const cacheKey = this.hash(text, size);
70-
this.cache.set(cacheKey, bmp);
71-
});
72+
createImageBitmap(canvas)
73+
.then((bmp) => {
74+
const cacheKey = this.hash(text, size);
75+
this.cache.set(cacheKey, bmp);
76+
})
77+
.catch(() => {});
7278
return canvas;
7379
}
7480

app/src/core/service/GlobalMenu.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,17 +582,16 @@ export async function onOpenFile(uri?: URI, source: string = "unknown") {
582582
return;
583583
}
584584
const project = new Project(uri);
585-
if (stage) {
586-
project.stage = deserialize(stage, project);
587-
console.log(project.stage);
588-
}
589585
const t = performance.now();
590586
loadAllServices(project);
591587
const loadServiceTime = performance.now() - t;
592588
await RecentFileManager.addRecentFileByUri(uri);
593589
toast.promise(project.init(), {
594590
loading: "正在打开文件...",
595591
success: () => {
592+
if (stage) {
593+
project.stage = deserialize(stage, project);
594+
}
596595
const readFileTime = performance.now() - t;
597596
store.set(projectsAtom, [...store.get(projectsAtom), project]);
598597
store.set(activeProjectAtom, project);

app/src/core/stage/ProjectUpgrader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Serialized } from "@/types/node";
2-
import { toast } from "sonner";
32
import { v4 as uuidv4 } from "uuid";
43

54
export namespace ProjectUpgrader {
@@ -393,7 +392,7 @@ export namespace ProjectUpgrader {
393392
const toNode = uuidMap.get(toUUID);
394393

395394
if (fromNode === undefined || toNode === undefined) {
396-
toast.warning(`边 ${association.uuid} 关联的节点不存在: ${fromUUID} -> ${toUUID}`);
395+
// toast.warning(`边 ${association.uuid} 关联的节点不存在: ${fromUUID} -> ${toUUID}`);
397396
continue;
398397
}
399398

0 commit comments

Comments
 (0)