Twinside / Rasterific

A drawing engine in Haskell
BSD 3-Clause "New" or "Revised" License
140 stars 11 forks source link

Hangs and eats all memory trying to render a complex diagram. #53

Closed kindaro closed 5 years ago

kindaro commented 5 years ago

Unfortunately, I do not have a short example. I am trying stuff with graphs, and one thing I did was to render a graph in some fashion. I discovered that, while I could vectorize it with the SVG back end, if I try to do the same with Rasterific, it eats all memory in an infinite loop. I did some profiling and I found out that the looping function is clipLine.

Here is the commit. You can run it with, for example, cabal run exes -- --output x.png --width 200. It hangs when I try it. If you replace clr489 example graph with, say, cyc3, it will render beautifully.

Here is the profiling log.

Please let me know if it hangs on your machine too, and if I can do anything else to help.

Twinside commented 5 years ago

Can you try to call dumpDrawing somehow a put the result somewhere?

Dump drawing should print-out the scene in nearly haskell, workable for debugging

kindaro commented 5 years ago
  1. I have no idea how to get that for you. I asked: diagrams/diagrams-rasterific#60.
  2. I found a ticket diagrams/diagrams-rasterific#39 that may be relevant.
Twinside commented 5 years ago

You have Infinity and NaNs n the dumped diagram:

(fill [LinePrim Line (V2 (-Infinity) (-Infinity)) (V2 (-Infinity) (-Infinity)),LinePrim Line (V2 (-Infinity) (-Infinity)) (V2 (-Infinity) (-Infinity)),LinePrim Line (V2 (-Infinity) (-Infinity)) (V2 (-Infinity) (-Infinity)),LinePrim Line (V2 (-Infinity) (-Infinity)) (V2 NaN NaN)] >>=

This is not filtered by Rasterific, and yeah, it makes the rendering go bonker.

kindaro commented 5 years ago

@Twinside Thank you for taking time to research this issue.

So what can be done?

I am not sure I can control this. The data I supply to the diagrams API is somewhat shady (like, sin pi shady), but it is legit. The same diagrams render flawlessly with SVG back end.

Can you explain to me what data type you are showing, and maybe post the code you used to obtain it, so that I can examine my various diagrams with it and locate what goes wrong?

Twinside commented 5 years ago

I've tried the SVG, and you have NaN and Infinity written in your SVG (that your browser probably ignore), I wouldn't call that flawless. The code is mostly the copy/past of Diagram.Rasterific with a call changed to dump the generated drawing, I've pushed it here.

I've added safegard to Rasterific for these cases, at least it shouldn't go into an infinite loop anymore.