在使用 Quartz 进行渲染期间,Graphviz 在 Mac 上崩溃
Graphviz crashes on Mac during render using Quartz
可以通过在 Mac OS High Sierra 和 运行 上安装 Graphviz 来重现该问题,并执行以下命令:
dot -v -Tpng:quartz /path/to/graph.dot -o /path/to/out.png
graph.dot
必须包含以下(最小)图形结构才能重现错误:
digraph {
imgnode[image="/path/to/some-image.png", label=""];
}
如下面的跟踪日志所示,当 dot
尝试将图像加载到图中时会引发错误。
使用 gvloadimage_quartz
在生成的图形 PNG 中嵌入 some-image.png
时会在 libgvplugin_quartz
中发生错误:
源代码:
https://gitlab.com/graphviz/graphviz/blob/master/plugin/quartz/gvloadimage_quartz.c 第 130 行。
升级Graphviz、Quartz或者MacOS好像没有任何效果,那么问题来了:为什么会出现这个错误,如何解决?这个错误是我造成的,还是 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
tl;博士:
您需要安装 graphviz
和 pango
插件。
brew reinstall graphviz --with-pango
解释:
在带有图像的图表中 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
}
}
检查 graphviz
是否有 pango
库:
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*
运行 brew reinstall graphviz --with-pango
安装 graphviz
和 pango
。 Brew 将为您设置一切。
如果 graphviz
已经有 pango
库,您可以将上面的行添加到您的 config6 文件中(即 /usr/local/Cellar/graphviz/<version>/lib/graphviz/config6
)。
实际上我在 3 月 12 日对这个问题投了赞成票,因为我的同事遇到了同样的问题。以上所有内容都是我在与遇到同样问题的经理一起调试此问题时学到的。我没有这个问题,因为我严格使用 MacPorts 进行包管理,MacPorts 默认包含 pango
。希望这有帮助。
编辑:bug report mentioned in the question 提供了相同的解决方案。
可以通过在 Mac OS High Sierra 和 运行 上安装 Graphviz 来重现该问题,并执行以下命令:
dot -v -Tpng:quartz /path/to/graph.dot -o /path/to/out.png
graph.dot
必须包含以下(最小)图形结构才能重现错误:
digraph {
imgnode[image="/path/to/some-image.png", label=""];
}
如下面的跟踪日志所示,当 dot
尝试将图像加载到图中时会引发错误。
使用 gvloadimage_quartz
在生成的图形 PNG 中嵌入 some-image.png
时会在 libgvplugin_quartz
中发生错误:
源代码: https://gitlab.com/graphviz/graphviz/blob/master/plugin/quartz/gvloadimage_quartz.c 第 130 行。
升级Graphviz、Quartz或者MacOS好像没有任何效果,那么问题来了:为什么会出现这个错误,如何解决?这个错误是我造成的,还是 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
tl;博士:
您需要安装 graphviz
和 pango
插件。
brew reinstall graphviz --with-pango
解释:
在带有图像的图表中 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
}
}
检查 graphviz
是否有 pango
库:
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*
运行 brew reinstall graphviz --with-pango
安装 graphviz
和 pango
。 Brew 将为您设置一切。
如果 graphviz
已经有 pango
库,您可以将上面的行添加到您的 config6 文件中(即 /usr/local/Cellar/graphviz/<version>/lib/graphviz/config6
)。
实际上我在 3 月 12 日对这个问题投了赞成票,因为我的同事遇到了同样的问题。以上所有内容都是我在与遇到同样问题的经理一起调试此问题时学到的。我没有这个问题,因为我严格使用 MacPorts 进行包管理,MacPorts 默认包含 pango
。希望这有帮助。
编辑:bug report mentioned in the question 提供了相同的解决方案。