hydra-synth / hydra

Livecoding networked visuals in the browser
https://hydra.ojack.xyz
GNU Affero General Public License v3.0
2.16k stars 264 forks source link

Forgetting to call a function will crash Hydra #35

Closed diegovdc closed 5 years ago

diegovdc commented 5 years ago

If working with functions it might be easy to forget a function call, which will fatally crash Hydra and will require a restart.

e.g.

var myfunc = () => 5
osc(() => myfunc).out()

Although this example is very simple, it is easy to forget a call when a function is curried.

var timeMod= mod => ({time}) =>  time%mod

osc(timeMod(60)).out() // all good

osc(params => timeMod(60)).out() //ups, forgot to pass params, will crash
ojack commented 5 years ago

ooowow this is great! Is this sort of a "best practices" thing, or something that could be somehow added to the software?

diegovdc commented 5 years ago

I think that when a function is used as an input to a src/function/etc... it's output, upon execution, should be validated so that it is a valid value. If an invalid value is returned, such as a function, a nice error could be thrown. (I have noticed that this crash also takes place is an undefined value is passed in).

At the very least the error should be catched, to prevent Hydra from crashing, which would not be at all nice in the context of a performance, (as it would require a restart).

I have been getting familiar with the codebase, but am yet to find where the execution of the functions happen. I now believe it is somewhere in hydra-synth. If you could point me where it takes place I'd be happy to open an pull request to work on a fix.

ojack commented 5 years ago

This is where the formatting of functions happens: https://github.com/ojack/hydra-synth/blob/6efcd8fefbcc49bc7fc1608a0ee58dc1f092a238/src/GeneratorFactory.js#L45

The executing of functions is handled within regl https://github.com/regl-project/regl

I am interested in understanding more about how this is happening!

ojack commented 5 years ago

Fixed at https://github.com/ojack/hydra-synth/pull/17