使用Quartz渲染时,Graphviz在Mac上崩溃

Lau*_*ent 6 macos rendering dot graphviz

通过在Mac OS High Sierra上安装Graphviz并运行以下命令可以重现此问题:

dot -v -Tpng:quartz /path/to/graph.dot -o /path/to/out.png 
Run Code Online (Sandbox Code Playgroud)

graph.dot 必须包含以下(最小)图形结构才能重现该错误:

digraph {
 imgnode[image="/path/to/some-image.png", label=""];
}
Run Code Online (Sandbox Code Playgroud)

如下面的tracelog所示,当dot尝试将图像加载到图形中时会引发错误.使用以下方法在生成的图形PNG中libgvplugin_quartz嵌入时发生错误:some-image.pnggvloadimage_quartz

源代码:https: //gitlab.com/graphviz/graphviz/blob/master/plugin/quartz/gvloadimage_quartz.c at 130.

升级Graphviz,Quartz或Mac OS似乎没有任何影响,所以问题是:为什么会出现这个错误以及如何修复它?是由我造成的错误还是Graphviz或Mac OS中的错误?我似乎无法在网上找到任何解决方案,除了一段时间没有活动的错误报告:https://github.com/Homebrew/homebrew-core/issues/18684

Dot 跟踪日志:

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
Run Code Online (Sandbox Code Playgroud)

Dan*_*rks 5

TL;博士:
你需要安装graphvizpango插件。

brew reinstall graphviz --with-pango
Run Code Online (Sandbox Code Playgroud)

说明:
在带有图像的图表中graphviz/dot正在尝试使用该pango插件。你可能已经在pango某处安装了它的库,但如果你这样做了,graphviz 不知道它。

你可以看看/usr/local/Cellar/graphviz/<version>/lib/graphviz/config6。如果您没有以下几行,则graphviz没有pango启用:

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
    }
}
Run Code Online (Sandbox Code Playgroud)

检查是否graphvizpango库:
ls -l /usr/local/Cellar/graphviz/2.40.1/lib/libgvplugin_pango*

如果你得到:

no matches found: /usr/local/Cellar/graphviz/2.40.1/lib/libgvpluhin_pango*
Run Code Online (Sandbox Code Playgroud)

运行brew reinstall graphviz --with-pango安装graphviz使用pango。Brew 将为您设置一切。

如果graphviz已经有pango库,您可以将上面的行添加到您的 config6 文件(即/usr/local/Cellar/graphviz/<version>/lib/graphviz/config6)。

我实际上在 3 月 12 日投票赞成这个问题,因为我的同事也遇到了同样的问题。以上都是我和我的经理一起调试这个问题时学到的,他有同样的问题。我没有这个问题,因为我严格使用 MacPorts 进行包管理,pango默认情况下包含 MacPorts 。希望这可以帮助。

编辑:问题中提到错误报告提供了相同的解决方案。