Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
fix shader error report
Browse files Browse the repository at this point in the history
  • Loading branch information
slmjkdbtl committed Oct 13, 2023
1 parent 527e26a commit ceb95b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/gfx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,9 @@ export class Shader {

if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) {
const vertError = gl.getShaderInfoLog(vertShader)
if (vertError) throw new Error("VERTEX SHADER " + vertError)
const fragError = gl.getShaderInfoLog(fragShader)
let msg = ""
if (vertError) msg += vertError
if (fragError) msg += fragError
throw new Error(msg)
if (fragError) throw new Error("FRAGMENT SHADER " + fragError)
}

gl.deleteShader(vertShader)
Expand Down
12 changes: 11 additions & 1 deletion src/kaboom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,17 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
): Shader {
const vcode = VERT_TEMPLATE.replace("{{user}}", vertSrc ?? DEF_VERT)
const fcode = FRAG_TEMPLATE.replace("{{user}}", fragSrc ?? DEF_FRAG)
return new Shader(ggl, vcode, fcode, VERTEX_FORMAT.map((vert) => vert.name))
try {
return new Shader(ggl, vcode, fcode, VERTEX_FORMAT.map((vert) => vert.name))
} catch (e) {
const lineOffset = 14
const fmtRegex = /(?<type>^\w+) SHADER ERROR: 0:(?<line>\d+): (?<msg>.+)/
const match = (e as Error).message.match(fmtRegex)
const line = Number(match.groups.line) - lineOffset
const msg = match.groups.msg.trim()
const ty = match.groups.type.toLowerCase()
throw new Error(`${ty} shader line ${line}: ${msg}`)
}
}

function makeFont(
Expand Down

0 comments on commit ceb95b7

Please sign in to comment.