Shaderlab detect shader with duplicate name (#1897)

* fix: detect shaders with duplicate name
This commit is contained in:
SwayYan
2023-12-08 10:58:32 +08:00
committed by GitHub
parent 18a384fda3
commit 34aee2f6c2
2 changed files with 11 additions and 0 deletions

View File

@@ -89,6 +89,9 @@ export class Shader {
}
const shaderInfo = Shader._shaderLab.parseShader(nameOrShaderSource);
if (shaderMap[shaderInfo.name]) {
throw `Shader named "${shaderInfo.name}" already exists.`;
}
const subShaderList = shaderInfo.subShaders.map((subShaderInfo) => {
const passList = subShaderInfo.passes.map((passInfo) => {
if (typeof passInfo === "string") {

View File

@@ -3,6 +3,7 @@ import { IShaderPassInfo, ISubShaderInfo } from "@galacean/engine-design";
import { Color } from "@galacean/engine-math";
import { ShaderLab } from "@galacean/engine-shader-lab";
import { glslValidate } from "./ShaderValidate";
import { Shader } from "@galacean/engine-core";
import chai, { expect } from "chai";
import spies from "chai-spies";
@@ -215,4 +216,11 @@ describe("ShaderLab", () => {
const demoShader = fs.readFileSync(path.join(__dirname, "shaders/glass.shader")).toString();
glslValidate(demoShader, shaderLab);
});
it("shader with duplicate name", () => {
const demoShader = fs.readFileSync(path.join(__dirname, "shaders/glass.shader")).toString();
(Shader as any)._shaderLab = shaderLab;
expect(Shader.create(demoShader) instanceof Shader).to.be.true;
expect(Shader.create.bind(null, demoShader)).to.throw('Shader named "Gem" already exists.');
});
});