f3d: PLY point clouds without a mesh crash the program
Describe the bug When trying to open a PLY that is just a colored point cloud, F3D says there’s no faces, but also crashes.
This is generated from RTAB-Map’s default export options. RTAB-Map’s viewer is also VTK so I believe this should work.
To Reproduce Steps to reproduce the behavior:
- Open the file
f3d dog.ply - Observe crash
Expected behavior A graceful exit at least (possibly supporting this type of PLY)
System Information:
- OS: Arch Linux
- GPU and GPU driver: 780M AMDGPU
F3D Information
F3D 3.0.0
F3D - A fast and minimalist 3D viewer
Version: 3.0.0-RC3-9-g8d72f2d0.
Build date: 2025-01-15 15:07:23.
Build system: Linux 64-bits.
Compiler: GNU 14.2.1.
Module ImGui: ON.
Module OpenEXR: ON.
Module Raytracing: ON.
VTK version: 9.4.1.
Copyright (C) 2019-2021 Kitware SAS.
Copyright (C) 2021-2024 Michael Migliore, Mathieu Westphal.
License BSD-3-Clause.
Additional context
[parker@parker-framework RTAB-Map]$ f3d dog.ply
Warning: Can't find property 'vertex_indices' in element 'face'
free(): double free detected in tcache 2
Aborted (core dumped)
File
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (16 by maintainers)
The last nightly fixes this issue: https://github.com/f3d-app/f3d/releases/tag/nightly
That code is OLD.
Thanks for investigating!
(btw we have a discord, feel free to join if thats your thing @exbluesbreaker : https://discord.f3d.app)
The fix has been merged in VTK, Ill bump VTK in our CI
https://gitlab.kitware.com/vtk/vtk/-/merge_requests/11961
It definitely is in the scope of F3D 😃
Ive seen that sometimes, with other files, i think its another bug.
Hello! So it seems I figure out the issue. ply file had those elements:
element vertex 139777- point cloud with a lot of pointselement face 0- no polygons (a bit uncommon for ply but could happen with like raw point cloud input)element camera 1The issue is the absence of polygons, which means also no properties are allocated, leaving props uninitialized. As a result, free is called on an invalid pointer, causing a crash. In
vtkPLY::add_property, properties are allocated, sovtkPLY::ply_closeshould checkelem->nprops > 0before freeingprops. Adding this check prevents the crash.Place of crash without check:
I will prepare MR for VTK with fix for it. The only thing which still bothers me, I may have found another issue—after successfully displaying a PLY file, pressing Ctrl+C sometimes leaves the app unresponsive instead of closing it, requiring a manual kill. I couldn’t reproduce this with a different file.
Also here is result of display of ply file. I doesn’t look exactly like dog to me, but who knows 😃
I joined, just didn’t yet talk there)
Hello!
I’m working on this problem. There are two ply element creations and deletions, but the second one involves uninitialized heap memory that later gets freed. I’ll continue tomorrow—I’ve spent some time on it. It seems there should be better initialization since the freeing code assumes all pointers are valid and doesn’t check for NULL(and pointer is not null just not initialized).
Overall it is not good to see C-style memory management in C++ code, but I guess there are reasons for it 😃