From 1d084918d7dddbb03a8457aeb952e6dc1436ebf6 Mon Sep 17 00:00:00 2001 From: Mirko Pecora Date: Thu, 14 Nov 2024 10:04:08 +0100 Subject: [PATCH] fix: added missing error messages --- src/core/renderers/webgl/WebGlCoreShader.ts | 6 ++++-- src/core/renderers/webgl/internal/ShaderUtils.ts | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/renderers/webgl/WebGlCoreShader.ts b/src/core/renderers/webgl/WebGlCoreShader.ts index f6f463bf..323f1dd1 100644 --- a/src/core/renderers/webgl/WebGlCoreShader.ts +++ b/src/core/renderers/webgl/WebGlCoreShader.ts @@ -143,12 +143,14 @@ export abstract class WebGlCoreShader extends CoreShader { fragmentSource, ); if (!vertexShader || !fragmentShader) { - throw new Error(); + throw new Error( + `Unable to create shader type: ${glw.FRAGMENT_SHADER}. Source: ${fragmentSource}`, + ); } const program = createProgram(glw, vertexShader, fragmentShader); if (!program) { - throw new Error(); + throw new Error('Unable to create program'); } this.program = program; diff --git a/src/core/renderers/webgl/internal/ShaderUtils.ts b/src/core/renderers/webgl/internal/ShaderUtils.ts index fd59e78b..1c682bca 100644 --- a/src/core/renderers/webgl/internal/ShaderUtils.ts +++ b/src/core/renderers/webgl/internal/ShaderUtils.ts @@ -100,11 +100,11 @@ export function createShader( ) { const shader = glw.createShader(type); if (!shader) { - throw new Error(); + throw new Error(`Unable to create shader type: ${type}. Source: ${source}`); } glw.shaderSource(shader, source); glw.compileShader(shader); - const success = glw.getShaderParameter(shader, glw.COMPILE_STATUS); + const success = !!glw.getShaderParameter(shader, glw.COMPILE_STATUS); if (success) { return shader; } @@ -120,12 +120,13 @@ export function createProgram( ) { const program = glw.createProgram(); if (!program) { - throw new Error(); + throw new Error('Unable to create program'); } + glw.attachShader(program, vertexShader); glw.attachShader(program, fragmentShader); glw.linkProgram(program); - const success = glw.getProgramParameter(program, glw.LINK_STATUS); + const success = !!glw.getProgramParameter(program, glw.LINK_STATUS); if (success) { return program; }