使用PCL过程中报出的aligned_free问题记录

近期在使用PCL库的过程中碰到了程序崩溃的问题,花了两三天的时间一直在解决该问题。
环境配置:
Windows11 + PCL 1.12.1 + VTK 9.1 + VS2019
爆出的问题:
在Memory.h文件的下述代码处爆出问题
/** \internal Frees memory allocated with aligned_malloc. */
EIGEN_DEVICE_FUNC inline void aligned_free(void *ptr)
{
#if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED
std::free(ptr);
#else
handmade_aligned_free(ptr);
#endif
}
使用PCL过程中报出的aligned_free问题记录_第1张图片
internal Frees memory allocated with aligned_malloc翻译过来应该是,内部释放使用aligned_malloc分配的内存。在VS输出窗口说是
HEAP[CircleTest.exe]: Invalid address specified to RtlValidateHeap( 0000025861220000, 00000258612B29D0 )
CircleTest.exe 已触发了一个断点。
针对这个问题,有人提到一个可能原因
在不同模块(工程)之间传递 C++ 类,而这两个模块用了不同的运行时库(Runtime Library)设置。
例如:EXE 模块调用 DLL 模块里传递 C++ 类的函数,但 DLL 模块使用静态链接(Release 是 Multi-threaded (/MT)、Debug 是 Multi-threaded Debug (/MTd))方式编译,而 EXE 模块使用动态链接(Release 是 Multi-threaded DLL (/MD)、Debug 是 Multi-threaded Debug DLL (/MDd))方式编译。
可以对比这两个模块的工程属性 - C/C++ - Code Generation - Runtime Library,看看设置是否一样,如果不一样要改成一样的。

但是经过检测,DLL和EXE工程的运行时库时一致的
使用PCL过程中报出的aligned_free问题记录_第2张图片
这个说法跟我的情况倒是一样的,因为我也是两个工程,一个工程用于封装成dll,另一个工程中调用这个dll工程中封装的C++类。
针对该问题,还看到一种处理方法,就是用更低版本的VS,更改平台工具集。
使用PCL过程中报出的aligned_free问题记录_第3张图片
甚至还有一种可能就是Debug和Release版本错乱。
关于他人的针对于DLL和EXE的运行时库不一样的解决方法

但是比较玄学的是,一模一样的代码,在别人电脑上不会崩溃。由此,开始怀疑是不是PCL库CMAKE出问题,只不过过去将近一年的使用没有发现罢了。于是果然卸载了PCL1.12.1,并选用AllInOne的方式重新安装PCL,这次不自己手动cmake。
结果,崩溃的问题还是出现。
此处先插入一条PCL库的下载地址,为了快捷和方便以及不想遇到各种麻烦直接选exe一键安装比较省事。
使用PCL过程中报出的aligned_free问题记录_第4张图片

于是,开始思考是不是栈区太小,于是使用VS开始手动扩大栈区大小,默认是1MB,改到了100MB,结果还是不行。
使用PCL过程中报出的aligned_free问题记录_第5张图片
后面重装了VS2019 也重装了PCL1.11.1,又装了PCL1.12.1,还是报同样的问题。开始怀疑是不是Win11的问题,后面干脆将整个工程拷贝到别人电脑上(也是win11),最终证明没问题。
后面按照同事的配置,一步步重新配置了一遍,问题好像得到了解决。
最初的PCL的系统环境变量如下:
使用PCL过程中报出的aligned_free问题记录_第6张图片
现在的环境变量:
使用PCL过程中报出的aligned_free问题记录_第7张图片
从上图可以看出,甚至同时配置了PCL1.11.1和1.12.1但是没有出问题,且第三方库只添加了VTK的路径。
还有个第三方库OpenNI2,这个一键安装就会自动添加上去,都不需要自己手动添加。
使用PCL过程中报出的aligned_free问题记录_第8张图片
包含目录配置:
使用PCL过程中报出的aligned_free问题记录_第9张图片
库目录:
使用PCL过程中报出的aligned_free问题记录_第10张图片
附加依赖项:

pcl_commond.lib
pcl_featuresd.lib
pcl_filtersd.lib
pcl_iod.lib
pcl_io_plyd.lib
pcl_kdtreed.lib
pcl_keypointsd.lib
pcl_mld.lib
pcl_octreed.lib
pcl_outofcored.lib
pcl_peopled.lib
pcl_recognitiond.lib
pcl_registrationd.lib
pcl_sample_consensusd.lib
pcl_searchd.lib
pcl_segmentationd.lib
pcl_stereod.lib
pcl_surfaced.lib
pcl_trackingd.lib
pcl_visualizationd.lib
vtkcgns-9.1d.lib
vtkChartsCore-9.1d.lib
vtkCommonColor-9.1d.lib
vtkCommonComputationalGeometry-9.1d.lib
vtkCommonCore-9.1d.lib
vtkCommonDataModel-9.1d.lib
vtkCommonExecutionModel-9.1d.lib
vtkCommonMath-9.1d.lib
vtkCommonMisc-9.1d.lib
vtkCommonSystem-9.1d.lib
vtkCommonTransforms-9.1d.lib
vtkDICOMParser-9.1d.lib
vtkDomainsChemistry-9.1d.lib
vtkDomainsChemistryOpenGL2-9.1d.lib
vtkdoubleconversion-9.1d.lib
vtkexodusII-9.1d.lib
vtkexpat-9.1d.lib
vtkFiltersAMR-9.1d.lib
vtkFiltersCore-9.1d.lib
vtkFiltersExtraction-9.1d.lib
vtkFiltersFlowPaths-9.1d.lib
vtkFiltersGeneral-9.1d.lib
vtkFiltersGeneric-9.1d.lib
vtkFiltersGeometry-9.1d.lib
vtkFiltersHybrid-9.1d.lib
vtkFiltersHyperTree-9.1d.lib
vtkFiltersImaging-9.1d.lib
vtkFiltersModeling-9.1d.lib
vtkFiltersParallel-9.1d.lib
vtkFiltersParallelImaging-9.1d.lib
vtkFiltersPoints-9.1d.lib
vtkFiltersProgrammable-9.1d.lib
vtkFiltersSelection-9.1d.lib
vtkFiltersSMP-9.1d.lib
vtkFiltersSources-9.1d.lib
vtkFiltersStatistics-9.1d.lib
vtkFiltersTexture-9.1d.lib
vtkFiltersTopology-9.1d.lib
vtkFiltersVerdict-9.1d.lib
vtkfmt-9.1d.lib
vtkfreetype-9.1d.lib
vtkGeovisCore-9.1d.lib
vtkgl2ps-9.1d.lib
vtkglew-9.1d.lib
vtkGUISupportQt-9.1d.lib
vtkGUISupportQtQuick-9.1d.lib
vtkGUISupportQtSQL-9.1d.lib
vtkhdf5-9.1d.lib
vtkhdf5_hl-9.1d.lib
vtkImagingColor-9.1d.lib
vtkImagingCore-9.1d.lib
vtkImagingFourier-9.1d.lib
vtkImagingGeneral-9.1d.lib
vtkImagingHybrid-9.1d.lib
vtkImagingMath-9.1d.lib
vtkImagingMorphological-9.1d.lib
vtkImagingSources-9.1d.lib
vtkImagingStatistics-9.1d.lib
vtkImagingStencil-9.1d.lib
vtkInfovisCore-9.1d.lib
vtkInfovisLayout-9.1d.lib
vtkInteractionImage-9.1d.lib
vtkInteractionStyle-9.1d.lib
vtkInteractionWidgets-9.1d.lib
vtkIOAMR-9.1d.lib
vtkIOAsynchronous-9.1d.lib
vtkIOCGNSReader-9.1d.lib
vtkIOChemistry-9.1d.lib
vtkIOCityGML-9.1d.lib
vtkIOCONVERGECFD-9.1d.lib
vtkIOCore-9.1d.lib
vtkIOEnSight-9.1d.lib
vtkIOExodus-9.1d.lib
vtkIOExport-9.1d.lib
vtkIOExportGL2PS-9.1d.lib
vtkIOExportPDF-9.1d.lib
vtkIOGeometry-9.1d.lib
vtkIOHDF-9.1d.lib
vtkIOImage-9.1d.lib
vtkIOImport-9.1d.lib
vtkIOInfovis-9.1d.lib
vtkIOIOSS-9.1d.lib
vtkIOLegacy-9.1d.lib
vtkIOLSDyna-9.1d.lib
vtkIOMINC-9.1d.lib
vtkIOMotionFX-9.1d.lib
vtkIOMovie-9.1d.lib
vtkIONetCDF-9.1d.lib
vtkIOOggTheora-9.1d.lib
vtkIOParallel-9.1d.lib
vtkIOParallelXML-9.1d.lib
vtkIOPLY-9.1d.lib
vtkIOSegY-9.1d.lib
vtkIOSQL-9.1d.lib
vtkioss-9.1d.lib
vtkIOTecplotTable-9.1d.lib
vtkIOVeraOut-9.1d.lib
vtkIOVideo-9.1d.lib
vtkIOXML-9.1d.lib
vtkIOXMLParser-9.1d.lib
vtkjpeg-9.1d.lib
vtkjsoncpp-9.1d.lib
vtkkissfft-9.1d.lib
vtklibharu-9.1d.lib
vtklibproj-9.1d.lib
vtklibxml2-9.1d.lib
vtkloguru-9.1d.lib
vtklz4-9.1d.lib
vtklzma-9.1d.lib
vtkmetaio-9.1d.lib
vtknetcdf-9.1d.lib
vtkogg-9.1d.lib
vtkParallelCore-9.1d.lib
vtkParallelDIY-9.1d.lib
vtkpng-9.1d.lib
vtkpugixml-9.1d.lib
vtkRenderingAnnotation-9.1d.lib
vtkRenderingContext2D-9.1d.lib
vtkRenderingContextOpenGL2-9.1d.lib
vtkRenderingCore-9.1d.lib
vtkRenderingFreeType-9.1d.lib
vtkRenderingGL2PSOpenGL2-9.1d.lib
vtkRenderingImage-9.1d.lib
vtkRenderingLabel-9.1d.lib
vtkRenderingLOD-9.1d.lib
vtkRenderingOpenGL2-9.1d.lib
vtkRenderingQt-9.1d.lib
vtkRenderingSceneGraph-9.1d.lib
vtkRenderingUI-9.1d.lib
vtkRenderingVolume-9.1d.lib
vtkRenderingVolumeOpenGL2-9.1d.lib
vtkRenderingVtkJS-9.1d.lib
vtksqlite-9.1d.lib
vtksys-9.1d.lib
vtkTestingRendering-9.1d.lib
vtktheora-9.1d.lib
vtktiff-9.1d.lib
vtkverdict-9.1d.lib
vtkViewsContext2D-9.1d.lib
vtkViewsCore-9.1d.lib
vtkViewsInfovis-9.1d.lib
vtkViewsQt-9.1d.lib
vtkWrappingTools-9.1d.lib
vtkzlib-9.1d.lib
libboost_atomic-vc142-mt-gd-x64-1_78.lib
libboost_bzip2-vc142-mt-gd-x64-1_78.lib
libboost_chrono-vc142-mt-gd-x64-1_78.lib
libboost_container-vc142-mt-gd-x64-1_78.lib
libboost_context-vc142-mt-gd-x64-1_78.lib
libboost_contract-vc142-mt-gd-x64-1_78.lib
libboost_coroutine-vc142-mt-gd-x64-1_78.lib
libboost_date_time-vc142-mt-gd-x64-1_78.lib
libboost_exception-vc142-mt-gd-x64-1_78.lib
libboost_filesystem-vc142-mt-gd-x64-1_78.lib
libboost_graph-vc142-mt-gd-x64-1_78.lib
libboost_graph_parallel-vc142-mt-gd-x64-1_78.lib
libboost_iostreams-vc142-mt-gd-x64-1_78.lib
libboost_locale-vc142-mt-gd-x64-1_78.lib
libboost_log-vc142-mt-gd-x64-1_78.lib
libboost_log_setup-vc142-mt-gd-x64-1_78.lib
libboost_math_c99-vc142-mt-gd-x64-1_78.lib
libboost_math_c99f-vc142-mt-gd-x64-1_78.lib
libboost_math_c99l-vc142-mt-gd-x64-1_78.lib
libboost_math_tr1-vc142-mt-gd-x64-1_78.lib
libboost_math_tr1f-vc142-mt-gd-x64-1_78.lib
libboost_math_tr1l-vc142-mt-gd-x64-1_78.lib
libboost_mpi-vc142-mt-gd-x64-1_78.lib
libboost_nowide-vc142-mt-gd-x64-1_78.lib
libboost_numpy38-vc142-mt-gd-x64-1_78.lib
libboost_prg_exec_monitor-vc142-mt-gd-x64-1_78.lib
libboost_program_options-vc142-mt-gd-x64-1_78.lib
libboost_python38-vc142-mt-gd-x64-1_78.lib
libboost_random-vc142-mt-gd-x64-1_78.lib
libboost_regex-vc142-mt-gd-x64-1_78.lib
libboost_serialization-vc142-mt-gd-x64-1_78.lib
libboost_system-vc142-mt-gd-x64-1_78.lib
libboost_test_exec_monitor-vc142-mt-gd-x64-1_78.lib
libboost_thread-vc142-mt-gd-x64-1_78.lib
libboost_timer-vc142-mt-gd-x64-1_78.lib
libboost_type_erasure-vc142-mt-gd-x64-1_78.lib
libboost_unit_test_framework-vc142-mt-gd-x64-1_78.lib
libboost_wave-vc142-mt-gd-x64-1_78.lib
libboost_wserialization-vc142-mt-gd-x64-1_78.lib
libboost_zlib-vc142-mt-gd-x64-1_78.lib
flann_cpp_s-gd.lib
flann_cpp-gd.lib
flann_s-gd.lib
flann-gd.lib
OpenNI2.lib
qhull_rd.lib
qhullcpp_d.lib
qhullstatic_d.lib
qhullstatic_rd.lib

其中VTK包含了自主编译的VTK的一些lib,比PCL直接安装的要多一些,详情请点击查看。
预处理器定义:
_DEBUG
_CONSOLE
BOOST_USE_WINDOWS_H
NOMINMAX
_CRT_SECURE_NO_DEPRECATE
_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS

以上是目前PCL1.12.1的全部配置,问题消失。相对比发现,其实系统环境变量变了,其余的应该是都没有进行本质上的改动。但不确定是否是系统环境变量引起的。

PCL1.11.1的附加依赖项如下:

pcl_commond.lib
pcl_featuresd.lib
pcl_filtersd.lib
pcl_iod.lib
pcl_io_plyd.lib
pcl_kdtreed.lib
pcl_keypointsd.lib
pcl_mld.lib
pcl_octreed.lib
pcl_outofcored.lib
pcl_peopled.lib
pcl_recognitiond.lib
pcl_registrationd.lib
pcl_sample_consensusd.lib
pcl_searchd.lib
pcl_segmentationd.lib
pcl_stereod.lib
pcl_surfaced.lib
pcl_trackingd.lib
pcl_visualizationd.lib
vtkChartsCore-8.2-gd.lib
vtkCommonColor-8.2-gd.lib
vtkCommonComputationalGeometry-8.2-gd.lib
vtkCommonCore-8.2-gd.lib
vtkCommonDataModel-8.2-gd.lib
vtkCommonExecutionModel-8.2-gd.lib
vtkCommonMath-8.2-gd.lib
vtkCommonMisc-8.2-gd.lib
vtkCommonSystem-8.2-gd.lib
vtkCommonTransforms-8.2-gd.lib
vtkDICOMParser-8.2-gd.lib
vtkDomainsChemistry-8.2-gd.lib
vtkDomainsChemistryOpenGL2-8.2-gd.lib
vtkdoubleconversion-8.2-gd.lib
vtkexodusII-8.2-gd.lib
vtkexpat-8.2-gd.lib
vtkFiltersAMR-8.2-gd.lib
vtkFiltersCore-8.2-gd.lib
vtkFiltersExtraction-8.2-gd.lib
vtkFiltersFlowPaths-8.2-gd.lib
vtkFiltersGeneral-8.2-gd.lib
vtkFiltersGeneric-8.2-gd.lib
vtkFiltersGeometry-8.2-gd.lib
vtkFiltersHybrid-8.2-gd.lib
vtkFiltersHyperTree-8.2-gd.lib
vtkFiltersImaging-8.2-gd.lib
vtkFiltersModeling-8.2-gd.lib
vtkFiltersParallel-8.2-gd.lib
vtkFiltersParallelImaging-8.2-gd.lib
vtkFiltersPoints-8.2-gd.lib
vtkFiltersProgrammable-8.2-gd.lib
vtkFiltersSelection-8.2-gd.lib
vtkFiltersSMP-8.2-gd.lib
vtkFiltersSources-8.2-gd.lib
vtkFiltersStatistics-8.2-gd.lib
vtkFiltersTexture-8.2-gd.lib
vtkFiltersTopology-8.2-gd.lib
vtkFiltersVerdict-8.2-gd.lib
vtkfreetype-8.2-gd.lib
vtkGeovisCore-8.2-gd.lib
vtkgl2ps-8.2-gd.lib
vtkglew-8.2-gd.lib
vtkGUISupportMFC-8.2-gd.lib
vtkhdf5-8.2-gd.lib
vtkhdf5_hl-8.2-gd.lib
vtkImagingColor-8.2-gd.lib
vtkImagingCore-8.2-gd.lib
vtkImagingFourier-8.2-gd.lib
vtkImagingGeneral-8.2-gd.lib
vtkImagingHybrid-8.2-gd.lib
vtkImagingMath-8.2-gd.lib
vtkImagingMorphological-8.2-gd.lib
vtkImagingSources-8.2-gd.lib
vtkImagingStatistics-8.2-gd.lib
vtkImagingStencil-8.2-gd.lib
vtkInfovisCore-8.2-gd.lib
vtkInfovisLayout-8.2-gd.lib
vtkInteractionImage-8.2-gd.lib
vtkInteractionStyle-8.2-gd.lib
vtkInteractionWidgets-8.2-gd.lib
vtkIOAMR-8.2-gd.lib
vtkIOAsynchronous-8.2-gd.lib
vtkIOCityGML-8.2-gd.lib
vtkIOCore-8.2-gd.lib
vtkIOEnSight-8.2-gd.lib
vtkIOExodus-8.2-gd.lib
vtkIOExport-8.2-gd.lib
vtkIOExportOpenGL2-8.2-gd.lib
vtkIOExportPDF-8.2-gd.lib
vtkIOGeometry-8.2-gd.lib
vtkIOImage-8.2-gd.lib
vtkIOImport-8.2-gd.lib
vtkIOInfovis-8.2-gd.lib
vtkIOLegacy-8.2-gd.lib
vtkIOLSDyna-8.2-gd.lib
vtkIOMINC-8.2-gd.lib
vtkIOMovie-8.2-gd.lib
vtkIONetCDF-8.2-gd.lib
vtkIOParallel-8.2-gd.lib
vtkIOParallelXML-8.2-gd.lib
vtkIOPLY-8.2-gd.lib
vtkIOSegY-8.2-gd.lib
vtkIOSQL-8.2-gd.lib
vtkIOTecplotTable-8.2-gd.lib
vtkIOVeraOut-8.2-gd.lib
vtkIOVideo-8.2-gd.lib
vtkIOXML-8.2-gd.lib
vtkIOXMLParser-8.2-gd.lib
vtkjpeg-8.2-gd.lib
vtkjsoncpp-8.2-gd.lib
vtklibharu-8.2-gd.lib
vtklibxml2-8.2-gd.lib
vtklz4-8.2-gd.lib
vtklzma-8.2-gd.lib
vtkmetaio-8.2-gd.lib
vtkNetCDF-8.2-gd.lib
vtkogg-8.2-gd.lib
vtkParallelCore-8.2-gd.lib
vtkpng-8.2-gd.lib
vtkproj-8.2-gd.lib
vtkpugixml-8.2-gd.lib
vtkRenderingAnnotation-8.2-gd.lib
vtkRenderingContext2D-8.2-gd.lib
vtkRenderingContextOpenGL2-8.2-gd.lib
vtkRenderingCore-8.2-gd.lib
vtkRenderingFreeType-8.2-gd.lib
vtkRenderingGL2PSOpenGL2-8.2-gd.lib
vtkRenderingImage-8.2-gd.lib
vtkRenderingLabel-8.2-gd.lib
vtkRenderingLOD-8.2-gd.lib
vtkRenderingOpenGL2-8.2-gd.lib
vtkRenderingVolume-8.2-gd.lib
vtkRenderingVolumeOpenGL2-8.2-gd.lib
vtksqlite-8.2-gd.lib
vtksys-8.2-gd.lib
vtktheora-8.2-gd.lib
vtktiff-8.2-gd.lib
vtkverdict-8.2-gd.lib
vtkViewsContext2D-8.2-gd.lib
vtkViewsCore-8.2-gd.lib
vtkViewsInfovis-8.2-gd.lib
vtkzlib-8.2-gd.lib
libboost_atomic-vc142-mt-gd-x64-1_74.lib
libboost_bzip2-vc142-mt-gd-x64-1_74.lib
libboost_chrono-vc142-mt-gd-x64-1_74.lib
libboost_container-vc142-mt-gd-x64-1_74.lib
libboost_context-vc142-mt-gd-x64-1_74.lib
libboost_contract-vc142-mt-gd-x64-1_74.lib
libboost_coroutine-vc142-mt-gd-x64-1_74.lib
libboost_date_time-vc142-mt-gd-x64-1_74.lib
libboost_exception-vc142-mt-gd-x64-1_74.lib
libboost_fiber-vc142-mt-gd-x64-1_74.lib
libboost_filesystem-vc142-mt-gd-x64-1_74.lib
libboost_graph-vc142-mt-gd-x64-1_74.lib
libboost_graph_parallel-vc142-mt-gd-x64-1_74.lib
libboost_iostreams-vc142-mt-gd-x64-1_74.lib
libboost_locale-vc142-mt-gd-x64-1_74.lib
libboost_log-vc142-mt-gd-x64-1_74.lib
libboost_log_setup-vc142-mt-gd-x64-1_74.lib
libboost_math_c99-vc142-mt-gd-x64-1_74.lib
libboost_math_c99f-vc142-mt-gd-x64-1_74.lib
libboost_math_c99l-vc142-mt-gd-x64-1_74.lib
libboost_math_tr1-vc142-mt-gd-x64-1_74.lib
libboost_math_tr1f-vc142-mt-gd-x64-1_74.lib
libboost_math_tr1l-vc142-mt-gd-x64-1_74.lib
libboost_mpi-vc142-mt-gd-x64-1_74.lib
libboost_nowide-vc142-mt-gd-x64-1_74.lib
libboost_numpy38-vc142-mt-gd-x64-1_74.lib
libboost_prg_exec_monitor-vc142-mt-gd-x64-1_74.lib
libboost_program_options-vc142-mt-gd-x64-1_74.lib
libboost_python38-vc142-mt-gd-x64-1_74.lib
libboost_random-vc142-mt-gd-x64-1_74.lib
libboost_regex-vc142-mt-gd-x64-1_74.lib
libboost_serialization-vc142-mt-gd-x64-1_74.lib
libboost_stacktrace_noop-vc142-mt-gd-x64-1_74.lib
libboost_stacktrace_windbg-vc142-mt-gd-x64-1_74.lib
libboost_stacktrace_windbg_cached-vc142-mt-gd-x64-1_74.lib
libboost_system-vc142-mt-gd-x64-1_74.lib
libboost_test_exec_monitor-vc142-mt-gd-x64-1_74.lib
libboost_thread-vc142-mt-gd-x64-1_74.lib
libboost_timer-vc142-mt-gd-x64-1_74.lib
libboost_type_erasure-vc142-mt-gd-x64-1_74.lib
libboost_unit_test_framework-vc142-mt-gd-x64-1_74.lib
libboost_wave-vc142-mt-gd-x64-1_74.lib
libboost_wserialization-vc142-mt-gd-x64-1_74.lib
libboost_zlib-vc142-mt-gd-x64-1_74.lib
flann-gd.lib
flann_cpp-gd.lib
flann_cpp_s-gd.lib
flann_s-gd.lib
OpenNI2.lib
qhullcpp_d.lib
qhullstatic_d.lib
qhullstatic_r_d.lib
qhull_d.lib
qhull_p_d.lib
qhull_r_d.lib

你可能感兴趣的:(c++,开发语言,PCL)