From 61ef85b2684304071089b0174cd06184d4c730d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=A6=82=E6=80=80=E5=BF=B5=EF=BC=88=E4=BA=91?= =?UTF-8?q?=E8=B0=8C=EF=BC=89?= Date: Mon, 9 Sep 2024 11:24:13 +0800 Subject: [PATCH] fix: webgl renderer has logical exception when updating attributes (#1768) (#1769) --- .changeset/healthy-boxes-train.md | 5 +++++ .../g-plugin-device-renderer/src/drawcalls/Image.ts | 4 ++++ .../src/drawcalls/Instanced.ts | 10 ++++++++++ .../src/drawcalls/InstancedFill.ts | 4 ++++ .../src/drawcalls/InstancedLine.ts | 4 ++++ .../src/drawcalls/InstancedPath.ts | 4 ++++ .../g-plugin-device-renderer/src/drawcalls/Mesh.ts | 4 ++++ packages/g-plugin-device-renderer/src/drawcalls/SDF.ts | 4 ++++ .../g-plugin-device-renderer/src/drawcalls/Text.ts | 2 ++ tsconfig.base.json | 4 ++-- 10 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 .changeset/healthy-boxes-train.md diff --git a/.changeset/healthy-boxes-train.md b/.changeset/healthy-boxes-train.md new file mode 100644 index 000000000..aeb11ff2d --- /dev/null +++ b/.changeset/healthy-boxes-train.md @@ -0,0 +1,5 @@ +--- +'@antv/g-plugin-device-renderer': patch +--- + +fix: webgl renderer has logical exception when updating attributes diff --git a/packages/g-plugin-device-renderer/src/drawcalls/Image.ts b/packages/g-plugin-device-renderer/src/drawcalls/Image.ts index 9aca987e8..e2e135d96 100644 --- a/packages/g-plugin-device-renderer/src/drawcalls/Image.ts +++ b/packages/g-plugin-device-renderer/src/drawcalls/Image.ts @@ -174,6 +174,10 @@ export class ImageDrawcall extends Instanced { name: string, value: any, ) { + if (objects.length === 0) { + return; + } + super.updateAttribute(objects, startIndex, name, value); this.updateBatchedAttribute(objects, startIndex, name, value); diff --git a/packages/g-plugin-device-renderer/src/drawcalls/Instanced.ts b/packages/g-plugin-device-renderer/src/drawcalls/Instanced.ts index 7c9806d0f..c6d7d00c9 100644 --- a/packages/g-plugin-device-renderer/src/drawcalls/Instanced.ts +++ b/packages/g-plugin-device-renderer/src/drawcalls/Instanced.ts @@ -878,6 +878,16 @@ export abstract class Instanced { this.geometryDirty = true; } } + + // fix https://github.com/antvis/G/issues/1768 + if (this.geometryDirty === true && this.objects.length !== 0) { + if (this.geometry) { + this.geometry.destroy(); + } + this.createGeometry(this.objects); + + this.geometryDirty = false; + } } changeRenderOrder(object: DisplayObject, renderOrder: number) { diff --git a/packages/g-plugin-device-renderer/src/drawcalls/InstancedFill.ts b/packages/g-plugin-device-renderer/src/drawcalls/InstancedFill.ts index a914da65e..2ea550cd0 100644 --- a/packages/g-plugin-device-renderer/src/drawcalls/InstancedFill.ts +++ b/packages/g-plugin-device-renderer/src/drawcalls/InstancedFill.ts @@ -206,6 +206,10 @@ export class InstancedFillDrawcall extends Instanced { name: string, value: any, ): void { + if (objects.length === 0) { + return; + } + super.updateAttribute(objects, startIndex, name, value); this.updateBatchedAttribute(objects, startIndex, name, value); diff --git a/packages/g-plugin-device-renderer/src/drawcalls/InstancedLine.ts b/packages/g-plugin-device-renderer/src/drawcalls/InstancedLine.ts index 0fd453b10..6a444aeb7 100644 --- a/packages/g-plugin-device-renderer/src/drawcalls/InstancedLine.ts +++ b/packages/g-plugin-device-renderer/src/drawcalls/InstancedLine.ts @@ -371,6 +371,10 @@ export class InstancedLineDrawcall extends Instanced { name: string, value: any, ) { + if (objects.length === 0) { + return; + } + super.updateAttribute(objects, startIndex, name, value); this.updateBatchedAttribute(objects, startIndex, name, value); diff --git a/packages/g-plugin-device-renderer/src/drawcalls/InstancedPath.ts b/packages/g-plugin-device-renderer/src/drawcalls/InstancedPath.ts index 3d22b0de0..3ae3b044f 100644 --- a/packages/g-plugin-device-renderer/src/drawcalls/InstancedPath.ts +++ b/packages/g-plugin-device-renderer/src/drawcalls/InstancedPath.ts @@ -338,6 +338,10 @@ export class InstancedPathDrawcall extends Instanced { name: string, value: any, ) { + if (objects.length === 0) { + return; + } + super.updateAttribute(objects, startIndex, name, value); this.updateBatchedAttribute(objects, startIndex, name, value); diff --git a/packages/g-plugin-device-renderer/src/drawcalls/Mesh.ts b/packages/g-plugin-device-renderer/src/drawcalls/Mesh.ts index 60f19c6a4..cc9fdc6bb 100644 --- a/packages/g-plugin-device-renderer/src/drawcalls/Mesh.ts +++ b/packages/g-plugin-device-renderer/src/drawcalls/Mesh.ts @@ -30,6 +30,10 @@ export class MeshDrawcall extends Instanced { name: string, value: any, ): void { + if (objects.length === 0) { + return; + } + super.updateAttribute(objects, startIndex, name, value); this.updateBatchedAttribute(objects, startIndex, name, value); } diff --git a/packages/g-plugin-device-renderer/src/drawcalls/SDF.ts b/packages/g-plugin-device-renderer/src/drawcalls/SDF.ts index 269dc67c1..c9527a0ba 100644 --- a/packages/g-plugin-device-renderer/src/drawcalls/SDF.ts +++ b/packages/g-plugin-device-renderer/src/drawcalls/SDF.ts @@ -155,6 +155,10 @@ export class SDFDrawcall extends Instanced { name: string, value: any, ) { + if (objects.length === 0) { + return; + } + super.updateAttribute(objects, startIndex, name, value); this.updateBatchedAttribute(objects, startIndex, name, value); diff --git a/packages/g-plugin-device-renderer/src/drawcalls/Text.ts b/packages/g-plugin-device-renderer/src/drawcalls/Text.ts index cde1f54c6..1a00e9e5e 100644 --- a/packages/g-plugin-device-renderer/src/drawcalls/Text.ts +++ b/packages/g-plugin-device-renderer/src/drawcalls/Text.ts @@ -347,6 +347,8 @@ export class TextDrawcall extends Instanced { return; } + super.updateAttribute(objects, startIndex, name, value); + if ( name === 'text' || name === 'fontFamily' || diff --git a/tsconfig.base.json b/tsconfig.base.json index 6351b4726..3bb390751 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,6 +1,7 @@ { "compilerOptions": { - "outDir": "./", + "rootDir": ".", + "outDir": ".", "module": "ESNext", "target": "es5", "jsx": "react", @@ -8,7 +9,6 @@ "experimentalDecorators": true, "declaration": true, "sourceMap": true, - "sourceRoot": ".", "allowSyntheticDefaultImports": true, "esModuleInterop": true, "isolatedModules": true,