Кажется, что работает рекурсивный алгоритм dfs, но я продолжаю получать ошибку «двойного освобождения или искажения (выхода)» в конце выполнения. Я не уверен, как это отладить.
Я уже пробовал Valgrind / GDB, я не могу понять, в чем именно проблема. Но это может быть связано с массивом «посещения».
Фрагмент, вызывающий проблему
void TriangleMesh::SearchColoredConnectedComponents(int v) {
this->visited[v] = true;
id_queue.push_back(v);
for (const auto& set : adjacency_list_[v]){
if(!this->visited[set]){
if((vertex_colors_[v][0] == vertex_colors_[set][0]) &&(vertex_colors_[v][1] == vertex_colors_[set][1]) && (vertex_colors_[v][2] == vertex_colors_[set][2])){
SearchColoredConnectedComponents(set);
}
}
}
}
std::vector<std::vector<int>> TriangleMesh::IdenticallyColoredConnectedComponents() {
std::vector<std::vector<int>> connect;
for (unsigned int i=0; i<adjacency_list_.size(); i++)
{
this->visited[i] = false;
}
for (unsigned int i=0; i<adjacency_list_.size(); i++)
{
if(this->visited[i] == false)
{
SearchColoredConnectedComponents(i);
std::sort(id_queue.begin(), id_queue.end());
connect.push_back(id_queue);
id_queue.clear();
}
}
std::sort(connect.begin(), connect.end());
return connect;
Сообщение Valgrind
==15795== Invalid write of size 1
==15795== at 0x18BB38: open3d::geometry::TriangleMesh::IdenticallyColoredConnectedComponents() (in /home/anushl9o5/Desktop/open3d_eg/build/TestVisualizer)
==15795== by 0x1690A8: main (in /home/anushl9o5/Desktop/open3d_eg/build/TestVisualizer)
==15795== Address 0x685a201 is 0 bytes after a block of size 1 alloc'd
==15795== at 0x4C3017F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==15795== by 0x16AF6C: std::__shared_ptr::__shared_ptr>(std::_Sp_make_shared_tag, std::allocator const&) (in /home/anushl9o5/Desktop/open3d_eg/build/TestVisualizer)
==15795== by 0x168FD6: main (in /home/anushl9o5/Desktop/open3d_eg/build/TestVisualizer)
==15795==
==15795== Invalid write of size 1
==15795== at 0x18BB45: open3d::geometry::TriangleMesh::IdenticallyColoredConnectedComponents() (in /home/anushl9o5/Desktop/open3d_eg/build/TestVisualizer)
==15795== by 0x1690A8: main (in /home/anushl9o5/Desktop/open3d_eg/build/TestVisualizer)
==15795== Address 0x685a202 is 1 bytes after a block of size 1 alloc'd
==15795== at 0x4C3017F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==15795== by 0x16AF6C: std::__shared_ptr::__shared_ptr>(std::_Sp_make_shared_tag, std::allocator const&) (in /home/anushl9o5/Desktop/open3d_eg/build/TestVisualizer)
==15795== by 0x168FD6: main (in /home/anushl9o5/Desktop/open3d_eg/build/TestVisualizer)
valgrind: m_mallocfree.c:307 (get_bszB_as_is): Assertion 'bszB_lo == bszB_hi' failed.
valgrind: Heap block lo/hi size mismatch: lo = 80, hi = 0.
This is probably caused by your program erroneously writing past the
end of a heap block and corrupting heap metadata. If you fix any
invalid writes reported by Memcheck, this assertion failure will
probably go away. Please try that before reporting this as a bug.