dbuenzli / vg

Declarative 2D vector graphics for OCaml
http://erratique.ch/software/vg
ISC License
88 stars 12 forks source link

end with black screen #8

Closed nodrygo closed 9 years ago

nodrygo commented 9 years ago

Hello, on Firefox 38 / Linux Mint 17 the demo : http://erratique.ch/software/vg/demos/rhtmlc end with black screen ( work on Chromium) the console say :

too much recursion rhtmlc.js:1693:0

don't know if this is a bug of vg

dbuenzli commented 9 years ago

No, in fact I think the problem is in Otfm, see this message.

I will have a look at this again at this when I do the next release at some point during this summer. js_of_ocaml also improved certain recursive use cases since then.

The annoying thing is that this seems to occurs only on Linux, at least FF on osx is fine.

But thanks for reminding me this.

nodrygo commented 9 years ago

OK, thanks for your answer

I am in phase of learning Ocaml and Ocsigen (for fun)

VG seem seem very interesting project to play with

best regard

2015-05-21 17:15 GMT+02:00 Daniel Bünzli notifications@github.com:

No, in fact I think the problem is in Otfm http://erratique.ch/software/otfm, see this message https://sympa.inria.fr/sympa/arc/caml-list/2013-09/msg00336.html.

I will have a look at this again at this when I do the next release at some point during this summer. js_of_ocaml also improved certain recursive use cases since then.

The annoying thing is that this seems to occurs only on Linux, at least FF on osx is fine.

But thanks for reminding me this.

— Reply to this email directly or view it on GitHub https://github.com/dbuenzli/vg/issues/8#issuecomment-104315001.

dbuenzli commented 9 years ago

Le jeudi, 21 mai 2015 à 17:20, nodrygo a écrit :

VG seem seem very interesting project to play with

You may want to have a look at this http://erratique.ch/tmp/2048.html which is rendered using Vg (a little bit slugish on FF iirc but fine in other browsers, again something else I should look into at some point). The rendering code can be found here https://github.com/ocamllabs/2048-tutorial

gasche commented 9 years ago

I hit the same issue this week-end. I was trying to help a beginner choose a library to draw sudoku grid, and Vg was summarily discarded because the "Sample images" link leads to a black screen (I tried under three different computers, all using Firefox -- the current one is using version 39.0.3). Having a gallery available (with easy way to get the complete code corresponding to each rendering) is a major usability plus for a graphic-related library.

dbuenzli commented 9 years ago

Having a gallery available (with easy way to get the complete code corresponding to each rendering)

Yes, that's exactly what this gives you. Somehow I still don't understand why the JavaScript engine of FF has different stack size on different OSes.

dbuenzli commented 9 years ago

And the difference is insane, on osx the maximal number of recursive calls I get is 40297 and on linux it's 5009.

gasche commented 9 years ago

If there is an OCaml-related way I could help (I don't know which code is involved, but maybe manually turning some of it in CPS style to avoid non-tail calls?), please let me know.

dbuenzli commented 9 years ago

@gasche Thanks for the offer but I'm not sure --- besides I don't want to distract you from that other thing you have to do... The problem I think but I'd have to investigate that a bit again is the monadic style of the OpenType font decoder Otfm.

What is a bit enraging here is that I actually designed Vg to be able to cope with the small JavaScript stack size problem by having non-blocking output with a cost model (see the limit argument here) and this is actually used by that failing sample code...

dbuenzli commented 9 years ago

Ok so this can be tracked specifically to the horizontal metrics font decoding that happens in the pdf renderer here.

Now this ends up calling Otfm.hmtx which boils to this. So we have these two self-recursive functions d_hmetric, d_hlsb one of which I guess blows the stack. I thought js_of_ocaml was able to optimize self-recursive functions, do the interleaved monadic binds prevents this ? /cc @drup @hhugo

dbuenzli commented 9 years ago

So it turns out that just inlining the error monad binds makes the problem disappear. See https://github.com/dbuenzli/otfm/commit/4ea6a34b884c5a680fa4333b79f6fd8117a0b8c0 and the current version online (0.8.1-17-g3a2767d) which no longer shows a black page, at least on Ubuntu 14.04 64 bits with FF 40.