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", }); diff --git a/src/ISFLineMapper.js b/src/ISFLineMapper.js index a63f7fc..6eb59b3 100644 --- a/src/ISFLineMapper.js +++ b/src/ISFLineMapper.js @@ -8,13 +8,18 @@ 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; 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/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 0c30404..77d2171 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; @@ -24,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 }); @@ -71,7 +71,7 @@ ISFRenderer.prototype.sourceChanged = function sourceChanged( } catch (e) { this.valid = false; this.error = e; - this.errorLine = LineMapper( + this.errorLine = lineNumber( e, this.fragmentShader, this.model.rawFragmentShader @@ -81,6 +81,7 @@ ISFRenderer.prototype.sourceChanged = function sourceChanged( this.fragmentShader, this.model.rawFragmentShader ); + } }; @@ -416,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();