mirror of
https://github.com/galacean/engine.git
synced 2026-06-21 19:02:50 +08:00
Replace throw with console.error to prevent blocking the main thread (#2077)
* chore: replace throw with console.error to prevent blocking the main thread
This commit is contained in:
@@ -91,7 +91,8 @@ export class Shader implements IReferable {
|
||||
|
||||
const shaderInfo = Shader._shaderLab.parseShader(nameOrShaderSource);
|
||||
if (shaderMap[shaderInfo.name]) {
|
||||
throw `Shader named "${shaderInfo.name}" already exists.`;
|
||||
console.error(`Shader named "${shaderInfo.name}" already exists.`);
|
||||
return;
|
||||
}
|
||||
const subShaderList = shaderInfo.subShaders.map((subShaderInfo) => {
|
||||
const passList = subShaderInfo.passes.map((passInfo) => {
|
||||
@@ -136,7 +137,8 @@ export class Shader implements IReferable {
|
||||
return shader;
|
||||
} else {
|
||||
if (shaderMap[nameOrShaderSource]) {
|
||||
throw `Shader named "${nameOrShaderSource}" already exists.`;
|
||||
console.error(`Shader named "${nameOrShaderSource}" already exists.`);
|
||||
return;
|
||||
}
|
||||
if (typeof vertexSourceOrShaderPassesOrSubShaders === "string") {
|
||||
const shaderPass = new ShaderPass(vertexSourceOrShaderPassesOrSubShaders, fragmentSource);
|
||||
|
||||
@@ -29,9 +29,10 @@ describe("Shader", () => {
|
||||
customShader = Shader.create("custom", [new SubShader("Default", [new ShaderPass(customVS, customFS)])]);
|
||||
|
||||
// Create same name shader
|
||||
expect(() => {
|
||||
Shader.create("custom", [new SubShader("Default", [new ShaderPass(customVS, customFS)])]);
|
||||
}).throw();
|
||||
const errorSpy = chai.spy.on(console, "error");
|
||||
Shader.create("custom", [new SubShader("Default", [new ShaderPass(customVS, customFS)])]);
|
||||
expect(errorSpy).to.have.been.called.with('Shader named "custom" already exists.');
|
||||
chai.spy.restore(console, "error");
|
||||
|
||||
// Create shader by empty SubShader array
|
||||
expect(() => {
|
||||
|
||||
@@ -228,8 +228,13 @@ describe("ShaderLab", () => {
|
||||
|
||||
const shaderInstance = Shader.create(demoShader);
|
||||
expect(shaderInstance).instanceOf(Shader);
|
||||
expect(Shader.create.bind(null, demoShader)).to.throw('Shader named "Gem" already exists.');
|
||||
|
||||
const errorSpy = chai.spy.on(console, "error");
|
||||
Shader.create(demoShader);
|
||||
expect(errorSpy).to.have.been.called.with('Shader named "Gem" already exists.');
|
||||
shaderInstance.destroy();
|
||||
chai.spy.restore(console, "error");
|
||||
|
||||
const sameNameShader = Shader.create(demoShader);
|
||||
expect(sameNameShader).instanceOf(Shader);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user