summaryrefslogtreecommitdiff
path: root/js/shader.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/shader.js')
-rw-r--r--js/shader.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/js/shader.js b/js/shader.js
index 19c049b..003f543 100644
--- a/js/shader.js
+++ b/js/shader.js
@@ -4,8 +4,16 @@ var shader_build = function(){
try {
var fn = new Function('x','y','t','d', fn_str)
shader = fn
+ error_highlight.off()
shade = shade_error_handling
} catch (e) {
+ try {
+ acorn.parse(fn_str)
+ } catch(e){
+ /* loc: {column: 0, line: 1} */
+ /* line is 1-based for some goddamn reason*/
+ error_highlight.on(e.loc.line-1)
+ }
throw Error ("Shader compilation error")
}
}
@@ -36,6 +44,9 @@ function shade_no_error_handling(frame, t){
cc.putImageData(imgData,0,0)
}
+var chrome_stack_regexp = /<anonymous>:([0-9]+)/;
+var firefox_stack_regexp = /:([0-9]+)$/;
+
function shade_error_handling(frame, t){
if (! t || isNaN(t)) throw Error ("No time specified")
if (! frame) throw Error ("No frame specified")
@@ -61,6 +72,20 @@ function shade_error_handling(frame, t){
}
}
catch(e){
+ var lines = (e.stack + "").split('\n')
+ if (lines[0].substr(0,10) === "anonymous@") { //firefox
+ var matches = lines[0].match(firefox_stack_regexp)
+ if (matches.length > 1) {
+ var line = parseInt(matches[1]) - 5
+ error_highlight.on(line)
+ }
+ } else if (lines.length > 1) { // attempt chrome match
+ var matches = lines[1].match(chrome_stack_regexp)
+ if (matches.length > 1) {
+ var line = parseInt(matches[1]) - 3
+ error_highlight.on(line)
+ }
+ }
// console.log(e.stack)
throw Error ("Shader execution error")
}
@@ -69,3 +94,6 @@ function shade_error_handling(frame, t){
}
shade = shade_error_handling
+
+// <anonymous>:4:11)
+// "anonymous@http://dither.local/js/shader.js:6" \ No newline at end of file