regl icon indicating copy to clipboard operation
regl copied to clipboard

Try-catch inside regl.frame() loop

Open caesarsol opened this issue 8 years ago • 11 comments

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?

caesarsol avatar Dec 16 '16 15:12 caesarsol

+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.

vorg avatar Dec 16 '16 18:12 vorg

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.

mikolalysenko avatar Dec 17 '16 05:12 mikolalysenko

Yeah, this is making the examples implode if you open devtools while typing things out in combination with the live reloading, especially on Firefox.

gregtatum avatar Dec 19 '16 21:12 gregtatum

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.

gregtatum avatar Dec 29 '17 20:12 gregtatum

@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?

gregtatum avatar Dec 31 '17 19:12 gregtatum

Alright, I think this is worth doing it. If you want to do the honors @gregtatum , go for it.

mikolalysenko avatar Jan 11 '18 21:01 mikolalysenko

Awesome! I think @nkint was interested too.

How can we solve the livereloading problem such as in the editable examples?

caesarsol avatar Jan 11 '18 21:01 caesarsol

Maybe this could be an optional feature, like we pass some extra flag to regl.frame().

mikolalysenko avatar Jan 11 '18 22:01 mikolalysenko

I'd still prefer it to be default even if it is a breaking change.

gregtatum avatar Jan 12 '18 20:01 gregtatum

hi, I know years has passed but this seems still applicable?

caesarsol avatar Apr 04 '22 16:04 caesarsol

Yes, it is still applicable.

gregtatum avatar Apr 06 '22 16:04 gregtatum