读取 OpenMesh 文件时断言 block_size == b 失败

Assertion block_size == b failed when reading an OpenMesh file

通过

读取OpenMesh文件时
OpenMesh::EPropHandleT<bool> prop_feature_edge;
mesh.add_property(prop_feature_edge, "feature");
OpenMesh::IO::read_mesh(mesh, "testmesh.om");

我收到错误

Assertion failed: block_size == b, file E:\JB\workspace\OpenMesh-Windows-Gitlab-master\c9e6b25f\src\OpenMesh\Core\IO\reader\OMReader.cc, line 564

我在源代码中查找了它,但并没有真正了解断言在那里检查的内容。问题可能与网格的不同属性有关 stored/loaded,但错误消息并不能真正帮助您了解问题出在哪里。

请注意,断言中的文件路径来自 openmesh 二进制文件,而不是我的项目路径。断言定义为 in this source source.

文件是使用

编写的
OpenMesh::EPropHandleT<bool> prop_feature_edge;
mesh.add_property(prop_feature_edge, "feature");
mesh.property(prop_feature_edge).set_persistent(true);
OpenMesh::IO::write_mesh(mesh, "testmesh.om");

在我的测试用例中,我编写了网格并再次重新读取它,但它失败了,因此字节顺序、默认选项或库版本应该没有差异。

相关堆栈跟踪:

    myProgram.exe!OpenMesh::IO::_OMReader_::restore_binary_custom_data(class std::basic_istream<char,struct std::char_traits<char> > &,class OpenMesh::BaseProperty *,unsigned __int64,bool)    Unknown
    myProgram.exe!OpenMesh::IO::_OMReader_::read_binary_edge_chunk(class std::basic_istream<char,struct std::char_traits<char> > &,class OpenMesh::IO::BaseImporter &,class OpenMesh::IO::Options &,bool)   Unknown
    myProgram.exe!OpenMesh::IO::_OMReader_::read_binary(class std::basic_istream<char,struct std::char_traits<char> > &,class OpenMesh::IO::BaseImporter &,class OpenMesh::IO::Options &)   Unknown
    myProgram.exe!OpenMesh::IO::_OMReader_::read(class std::basic_istream<char,struct std::char_traits<char> > &,class OpenMesh::IO::BaseImporter &,class OpenMesh::IO::Options &)  Unknown
    myProgram.exe!OpenMesh::IO::_OMReader_::read(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class OpenMesh::IO::BaseImporter &,class OpenMesh::IO::Options &)  Unknown
    myProgram.exe!OpenMesh::IO::_IOManager_::read(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class OpenMesh::IO::BaseImporter &,class OpenMesh::IO::Options &) Unknown
    myProgram.exe!OpenMesh::IO::read_mesh<OpenMesh::TriMesh_ArrayKernelT<OpenMesh::DefaultTraits> >(OpenMesh::TriMesh_ArrayKernelT<OpenMesh::DefaultTraits> & _mesh, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _filename, OpenMesh::IO::Options & _opt, bool _clear) Line 141    C++
    myProgram.exe!main(int argc, char * * argv) Line 479    C++
    [External Code] 

所以这看起来真的像是自定义属性中的一些错误的尺寸计算。 我复制了添加自定义属性的代码,并在读取网格之前从写入网格请求现有属性(如面状态和顶点颜色),以确保具有相同的网格属性,但它仍然崩溃。

比较配置的网格的属性它们似乎是相同的:

properties before writing
3 vprops:
  v:points
  <vprop>
  v:colors
1 hprops:
  <hprop>
2 eprops:
  <eprop>
  feature, persistent
2 fprops:
  <fprop>
  f:status
0 mprops:
#bytes written: 169006

properties before reading
3 vprops:
  v:points
  <vprop>
  v:colors
1 hprops:
  <hprop>
2 eprops:
  <eprop>
  feature, persistent
2 fprops:
  <fprop>
  f:status
0 mprops:

我找到了问题的解决方案。

在写作之前我删除了面孔。这需要在脸上有一个(非永久性)状态标志,需要通过 request_face_status().

添加

这很好用,collect_garbage() 正确删除了面,但没有删除相应的边。这导致边数在写入之前和加载之后不同,而存储的 feature 属性 可能与之前的大小相同,与加载的边数不匹配。

解决方法是添加

mesh.request_edge_status()

除了 mesh.request_face_status()。根据网格上的操作,使用 mesh.request_vertex_status() 可能也是个好主意。