regl
regl copied to clipboard
Try-catch inside regl.frame() loop
When an error happens inside the regl.frame loop, to prevent logging it again and again infinitely, I usually do:
function frameCatch (frameFunc) {
const loop = regl.frame((...args) => {
try {
frameFunc(...args)
} catch (err) {
loop.cancel()
throw err
}
})
}
// Then use frameCatch instead of regl.frame
What would you think about integrating it in regl.frame itself?
+1. I keep writing this code over and over again (I think twice today already). If that's something you need to handle in production to stop loop from cancelling then you would add catch once at the end of the project, not in every single prototype with shaders breaking every 10min.
I think this makes sense, though it would be a breaking change.
That said, I think this is also sufficiently under specified that merging it in with appropriate amendments to the docs would be ok. If either of you wants to write a PR I'll review and merge it in.
Yeah, this is making the examples implode if you open devtools while typing things out in combination with the live reloading, especially on Firefox.
I may take this as a first bug. I've been reading through the issues and there seems to be a consensus that the desired behavior is to go ahead and implement this under the frame command rather than introduce a frameSafe command.
@mikolalysenko you mentioned on gitter that you didn't want any breaking changes, but this seems to be a real big annoyance (it's also one of my big pet peeves). Would you be ok if we went forward with this?
Alright, I think this is worth doing it. If you want to do the honors @gregtatum , go for it.
Awesome! I think @nkint was interested too.
How can we solve the livereloading problem such as in the editable examples?
Maybe this could be an optional feature, like we pass some extra flag to regl.frame().
I'd still prefer it to be default even if it is a breaking change.
hi, I know years has passed but this seems still applicable?
Yes, it is still applicable.