From 48d0cf43638bb1dea19c967d06455a9f5f0b2f3f Mon Sep 17 00:00:00 2001 From: Tim Pietrusky Date: Fri, 29 Oct 2021 12:02:11 +0200 Subject: [PATCH 1/4] fix(error-handling): throw the error --- src/ISFGLProgram.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ISFGLProgram.js b/src/ISFGLProgram.js index 26dffe1..ca98b21 100644 --- a/src/ISFGLProgram.js +++ b/src/ISFGLProgram.js @@ -55,9 +55,8 @@ ISFGLProgram.prototype.createShader = function createShader(src, type) { const compiled = this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS); if (!compiled) { const lastError = this.gl.getShaderInfoLog(shader); - throw new Error({ - message: lastError, - type: "shader", + throw ({ + message: lastError }); } return shader; @@ -74,7 +73,7 @@ ISFGLProgram.prototype.createProgram = function createProgram( const linked = this.gl.getProgramParameter(program, this.gl.LINK_STATUS); if (!linked) { const lastError = this.gl.getProgramInfoLog(program); - throw new Error({ + throw ({ message: lastError, type: "program", }); From 54426c0796bf0c4a2553e6693857a5e8a97709c0 Mon Sep 17 00:00:00 2001 From: Tim Pietrusky Date: Fri, 29 Oct 2021 12:18:17 +0200 Subject: [PATCH 2/4] refactor(error-handling): use function instead of object --- src/ISFLineMapper.js | 2 +- src/ISFRenderer.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ISFLineMapper.js b/src/ISFLineMapper.js index a63f7fc..703cbdf 100644 --- a/src/ISFLineMapper.js +++ b/src/ISFLineMapper.js @@ -8,7 +8,7 @@ function getMainLine(src) { return -1; } -export default function ISFLineMapper(error, glsl, isf) { +export function lineNumber(error, glsl, isf) { const glslMainLine = getMainLine(glsl); const isfMainLine = getMainLine(isf); const regex = /ERROR: (\d+):(\d+): (.*)/g; diff --git a/src/ISFRenderer.js b/src/ISFRenderer.js index 0c30404..cd7b152 100644 --- a/src/ISFRenderer.js +++ b/src/ISFRenderer.js @@ -5,11 +5,9 @@ import ISFGLProgram from "./ISFGLProgram"; import ISFBuffer from "./ISFBuffer"; import ISFParser from "./ISFParser"; import ISFTexture from "./ISFTexture"; -import LineMapper from "./ISFLineMapper"; +import { lineNumber, correctedLineErrors } from "./ISFLineMapper"; import { ISFAudio, ISFAudioTexture } from "./ISFAudio"; -const { correctedLineErrors } = LineMapper; - const mathJsEval = math.eval; let globalAudioInstance; @@ -69,9 +67,10 @@ ISFRenderer.prototype.sourceChanged = function sourceChanged( } } } catch (e) { + debugger this.valid = false; this.error = e; - this.errorLine = LineMapper( + this.errorLine = lineNumber( e, this.fragmentShader, this.model.rawFragmentShader @@ -81,6 +80,7 @@ ISFRenderer.prototype.sourceChanged = function sourceChanged( this.fragmentShader, this.model.rawFragmentShader ); + } }; From 1d093e2957c95c1db6d4acfd61d1b42f80f63aa7 Mon Sep 17 00:00:00 2001 From: Tim Pietrusky Date: Fri, 29 Oct 2021 12:24:02 +0200 Subject: [PATCH 3/4] fix(error-handling): handle cases where no line number is available --- src/ISFLineMapper.js | 9 +++++++-- src/ISFRenderer.js | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ISFLineMapper.js b/src/ISFLineMapper.js index 703cbdf..6eb59b3 100644 --- a/src/ISFLineMapper.js +++ b/src/ISFLineMapper.js @@ -13,8 +13,13 @@ export function lineNumber(error, glsl, isf) { const isfMainLine = getMainLine(isf); const regex = /ERROR: (\d+):(\d+): (.*)/g; const matches = regex.exec(error.message); - const glslErrorLine = matches[2]; - const isfErrorLine = parseInt(glslErrorLine, 10) + isfMainLine - glslMainLine; + let isfErrorLine = -1; + + // Sometimes we get errors that don't contain a lineNumber + if (matches !== null) { + const glslErrorLine = matches[2]; + isfErrorLine = parseInt(glslErrorLine, 10) + isfMainLine - glslMainLine; + } return isfErrorLine; } diff --git a/src/ISFRenderer.js b/src/ISFRenderer.js index cd7b152..5c43dfb 100644 --- a/src/ISFRenderer.js +++ b/src/ISFRenderer.js @@ -67,7 +67,6 @@ ISFRenderer.prototype.sourceChanged = function sourceChanged( } } } catch (e) { - debugger this.valid = false; this.error = e; this.errorLine = lineNumber( From 78b62b6f4c787b870852df4c8e7b1131e331d8a6 Mon Sep 17 00:00:00 2001 From: TimPietrusky Date: Wed, 10 Aug 2022 13:17:23 +0200 Subject: [PATCH 4/4] feat(audio): only update the audio-textures if there is an audio input --- src/ISFParser.js | 8 ++++++++ src/ISFRenderer.js | 22 ++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/ISFParser.js b/src/ISFParser.js index 5b9d83e..ffd9e6f 100644 --- a/src/ISFParser.js +++ b/src/ISFParser.js @@ -24,6 +24,9 @@ const typeUniformMap = { const ISFParser = function ISFParser() {}; ISFParser.prototype.parse = function parse(rawFragmentShader, rawVertexShader) { + // Indicates if the shader is using an audio-input (audio or audioFFT) + this.hasAudio = false + try { this.valid = true; this.rawFragmentShader = rawFragmentShader; @@ -80,6 +83,11 @@ ISFParser.prototype.generateShaders = function generateShaders() { this.uniformDefs = ""; for (let i = 0; i < this.inputs.length; i += 1) { this.addUniform(this.inputs[i]); + + // Make sure to identify if this shader has audio + if (this.inputs[i].TYPE === "audio" || this.inputs[i].TYPE === "audioFFT") { + this.hasAudio = true; + } } for (let i = 0; i < this.passes.length; i += 1) { diff --git a/src/ISFRenderer.js b/src/ISFRenderer.js index 5c43dfb..77d2171 100644 --- a/src/ISFRenderer.js +++ b/src/ISFRenderer.js @@ -22,7 +22,9 @@ function ISFRenderer(gl, options = {}) { this.frameIndex = 0; this.audioTextureInstances = []; - const { useWebAudio, fftSize } = options; + const { useWebAudio, fftSize, hasAudio } = options; + + this.hasAudio = hasAudio; if (!globalAudioInstance) { globalAudioInstance = new ISFAudio({ useWebAudio, fftSize }); @@ -415,14 +417,18 @@ ISFRenderer.prototype.setDateUniforms = function setDateUniforms() { }; ISFRenderer.prototype.draw = function draw(destination) { - this.audio.updateWebAudio(); - this.audioTextureInstances.forEach((localInstanceData) => { - const instance = this.audio.audioTextureInstances[localInstanceData.id]; - - instance.update(); - this.setValue(localInstanceData.inputName, instance.context.canvas); - }); + // Don't update the audio instances if the shader is not using any audio inputs + if (this.hasAudio) { + this.audio.updateWebAudio(); + this.audioTextureInstances.forEach((localInstanceData) => { + const instance = this.audio.audioTextureInstances[localInstanceData.id]; + + instance.update(); + + this.setValue(localInstanceData.inputName, instance.context.canvas); + }); + } this.contextState.reset(); this.program.use();