Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz crashes on Mac during render using Quartz

The problem can be reproduced by installing Graphviz on Mac OS High Sierra and running the following command:

dot -v -Tpng:quartz /path/to/graph.dot -o /path/to/out.png 

graph.dot must contain the following (minimal) graph structure to reproduce the bug:

digraph {
 imgnode[image="/path/to/some-image.png", label=""];
}

As seen in the tracelog below, the error is raised when dot tries to load an image into the graph. The error takes place in libgvplugin_quartz when embedding some-image.png in the resulting graph PNG using gvloadimage_quartz:

Source code: https://gitlab.com/graphviz/graphviz/blob/master/plugin/quartz/gvloadimage_quartz.c at line 130.

Upgrading Graphviz, Quartz or Mac OS does not seem to have any effect, so the question is: why does this error occur and how to fix it? Is the error caused by me or is this a bug in Graphviz or Mac OS? I cannot seem to find any solutions online except for a bug report which hasn't been active for a while: https://github.com/Homebrew/homebrew-core/issues/18684

Dot tracelog:

dot[11528:2474068] +[__NSCFConstantString length]: unrecognized selector sent to class 0x7fffa240c578
dot[11528:2474068] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[__NSCFConstantString length]: unrecognized selector sent to class 0x7fffa240c578'
*** First throw call stack:
(
 0   CoreFoundation                      0x00007fff4811200b __exceptionPreprocess + 171
 1   libobjc.A.dylib                     0x00007fff6ececc76 objc_exception_throw + 48
 2   CoreFoundation                      0x00007fff481aac14 +[NSObject(NSObject) doesNotRecognizeSelector:] + 132
 3   CoreFoundation                      0x00007fff480883f0 ___forwarding___ + 1456
 4   CoreFoundation                      0x00007fff48087db8 _CF_forwarding_prep_0 + 120
 5   CoreFoundation                      0x00007fff48025914 CFStringCompareWithOptionsAndLocale + 68
 6   ImageIO                             0x00007fff4a976ad0 _ZN17IIO_ReaderHandler15readerForUTTypeEPK10__CFString + 52
 7   ImageIO                             0x00007fff4a94ac94 _ZN14IIOImageSource14doBindToReaderEv + 434
 8   ImageIO                             0x00007fff4a94b30d _ZN14IIOImageSource18createImageAtIndexEmP13IIODictionary + 39
 9   ImageIO                             0x00007fff4a93906b CGImageSourceCreateImageAtIndex + 237
 10  libgvplugin_quartz.6.dylib          0x0000000108ef648b memory_data_consumer_get_byte_pointer + 699
 11  libgvc.6.dylib                      0x0000000108e26afa gvloadimage + 250
 12  libgvc.6.dylib                      0x0000000108e24e58 gvrender_usershape + 1080
 13  libgvc.6.dylib                      0x0000000108e4cd5a html_port + 4186
 14  libgvc.6.dylib                      0x0000000108e492cc emit_html_label + 524
 15  libgvc.6.dylib                      0x0000000108e50569 emit_label + 57
 16  libgvc.6.dylib                      0x0000000108e5f187 find_user_shape + 10151
 17  libgvc.6.dylib                      0x0000000108e3edda getObjId + 2778
 18  libgvc.6.dylib                      0x0000000108e435ae emit_graph + 3998
 19  libgvc.6.dylib                      0x0000000108e45a51 gvRenderJobs + 6673
 20  dot                                 0x0000000108e1dc95 dot + 11413
 21  libdyld.dylib                       0x00007fff6f8dc115 start + 1
 22  ???                                 0x0000000000000004 0x0 + 4
)
libc++abi.dylib: terminating with uncaught exception of type NSException
like image 634
Laurent Avatar asked Jan 22 '18 14:01

Laurent


1 Answers

tl;dr:
You need to install graphviz with the pango plugin.

brew reinstall graphviz --with-pango

Explanation:
In your graph with images graphviz/dot is trying to use the pango plugin. You may already have pango and its libs installed somewhere, but if you do, graphviz does not know about it.

You can take a look at /usr/local/Cellar/graphviz/<version>/lib/graphviz/config6. If you don't have the following lines, then graphviz does not have pango enabled:

libgvplugin_pango.6.dylib cairo {
    render {
        cairo 10
    }
    textlayout {
    textlayout 10
    }
    loadimage {
        png:cairo 1
        png:lasi 2
        png:ps 2
    }
    device {
        png:cairo 10
        ps:cairo -10
        pdf:cairo 10
        svg:cairo -10
    }
}

To check if graphviz has the pango libs:
ls -l /usr/local/Cellar/graphviz/2.40.1/lib/libgvplugin_pango*

If you get:

no matches found: /usr/local/Cellar/graphviz/2.40.1/lib/libgvpluhin_pango*

Run brew reinstall graphviz --with-pango to install graphviz with pango. Brew will set everything up for you.

If graphviz already has pango libs you can add the lines above to your config6 file (i.e. /usr/local/Cellar/graphviz/<version>/lib/graphviz/config6).

I actually upvoted this question on March 12 because my coworker was having the same problem. Everything above is what I learned debugging this issue with my manager, who had the same problem. I did not have this issue because I strictly use MacPorts for package management, and MacPorts included pango by default. Hope this helps.

Edit: The bug report mentioned in the question offers the same solution.

like image 139
Daniel Marks Avatar answered Oct 24 '22 07:10

Daniel Marks