Graphviz crashes on Mac during render using Quartz
Asked Answered
P

1

8

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
Premiership answered 22/1, 2018 at 14:31 Comment(0)
S
5

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.

Satiated answered 20/4, 2018 at 18:50 Comment(8)
Hi Daniel, thanks for looking at it. Does this mean that the Quartz renderer depends on Cairo? I thought they were independent rendering mechanisms. My workaround was also to install Graphviz --with-pango and in addition commenting out the Quartz plugin lines in config6 just to make sure it doesn't crash. I hope they patch it soon.Premiership
Hey Laurent, I am sorry, I am not familiar with graphviz/dot under the hood. While looking into this problem, our main question was, "Why does it work when installed via MacPorts and break when installed via brew?" This led us to comparing versions, then plugins, then configs. I did a diff on my managers config and mine, and started commenting mine out to see which lacking plug-in was problematic. I found that it was pango and that my teammates did not have the pango libs in their graphviz lib directory. We saw the --with-pango option and my manager tried it "just for smiles" and it worked!Satiated
--with-pango no more supported check this issue for detailGoodyear
Is this still an issue then? It may just work as expected without the --with-pango option now. I don't have brew installed, and I am not going to install it to check. The MacPorts graphviz package has always worked as expected for me.Satiated
It's still an issue, the same exception is still emitted with brew install graphvizSoliloquy
Also copying the lines starting libgvplugin_pango.6.dylib cairo into the config6 file doesn't work, since there is no libgvplugin_pango.6.dylib library, I also tried brew install pango and replacing the libgvplugin_pango.6.dylib with libpango-1.0.0.dylib and /usr/local/Cellar/pango/1.44.7/lib/libpango-1.0.0.dylib but none of these worked either...Soliloquy
And the "Edit" link to github.com/Homebrew/homebrew-core/issues/18684 just recommends using brew reinstall graphviz --with-pango, which doesn't workSoliloquy
@JamesMitchell I think the last time I tried this, the homebrew graphviz worked out of the box for my needs, but I'll have to setup another machine just to test this because I don't want to mess with my environment just to troubleshoot. My spares are in the office so it'll have to wait until Covid-19 has settled down.Satiated

© 2022 - 2024 — McMap. All rights reserved.