Skip to content

Commit

Permalink
Added actual error parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Raikiri committed Oct 20, 2024
1 parent 28c4a81 commit 75bcaa1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 31 deletions.
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"vite": "^5.4.8"
},
"dependencies": {
"@shaderfrog/glsl-parser": "^5.3.2",
"monaco-editor": "^0.52.0",
"terser": "^5.36.0"
}
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ function SetEditorSquiggies(
visibleRange.startLineNumber > line ||
visibleRange.endLineNumber < line
) {
editor.revealLineInCenter(line)
if(line > 0) //line = 0 usually means we failed to find it
editor.revealLineInCenter(line)
}
}
}
Expand Down
44 changes: 24 additions & 20 deletions src/webgl-shader-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { GlslSyntaxError, parser } from "@shaderfrog/glsl-parser"

export type SuccessfulCompilationResult = {
program : WebGLProgram,
type: 'success'
Expand All @@ -12,6 +10,28 @@ export type FailedCompilationResult = {

export type CompilationResult = SuccessfulCompilationResult | FailedCompilationResult

type ErrLocation = {
line : number,
column : number
}
function ParseGlslErrorLine(errorMessage : string) : ErrLocation
{
//error location in format "something:line"
//nobody knows what "something" there means
const pattern = /(\d+)\s*:\s*(\d+)/;

// Find the match
const match = errorMessage.match(pattern);

if (match) {
const something = parseInt(match[1], 10);

Check failure on line 27 in src/webgl-shader-compiler.ts

View workflow job for this annotation

GitHub Actions / deploy

'something' is declared but its value is never read.
const line = parseInt(match[2], 10);
return {line, column : 0}
} else {
return {line : 0, column : 0}
}
}

// TODO: we can probably reuse the vertex shader...
export function CreateRasterProgram(
gl: WebGL2RenderingContext,
Expand All @@ -35,30 +55,14 @@ export function CreateRasterProgram(
}
}

try {
parser.parse(frag)
} catch (e: any) {
// Assume this is a syntax error
if (e.location && e.message) {
const syntaxError = e as GlslSyntaxError

return {
type: "fail",
msg: syntaxError.message,
// TODO: this includes a range that will be useful to show in the editor
line: syntaxError.location.start.line,
}
}
}

gl.shaderSource(fragShader, frag)
gl.compileShader(fragShader)
if (!gl.getShaderParameter(fragShader, gl.COMPILE_STATUS)) {
const err = gl.getShaderInfoLog(fragShader);
return {
type : 'fail',
msg : 'Failed to compile the fragment shader: '.concat(err ? err : 'no error, actually'),
line: 0
msg : 'FS: '.concat(err ? err : 'no error, actually'),
line: ParseGlslErrorLine(err ? err : "").line
}
}

Expand Down

0 comments on commit 75bcaa1

Please sign in to comment.