Access violation in vtkCommonInformationKeyManager::ClassFinalize() on dynamic library unloading (at least 8.2.0 and 9.0.1)
When VTK is loaded and unloaded dynamically under Windows, there is an Access Violation in vtkCommonInformationKeyManager::ClassFinalize()
.
Test code below. There might be a more minimalistic way to showcase the problem. I came in from using the Point Cloud Library (depends on VTK) and circled the problem to loading and unloading vtkFiltersGeneral-9.0(d).dll
. The Access Violation then triggers in vtkCommonCore-9.0(d).dll
. Just loading and unloading vtkCommonCore-9.0(d).dll
does not trigger the Access Violation.
The issue was initially observed in VTK 8.2 binaries that shipped with PCL. It was then confirmed in own builds of VTK 8.2.0 and VTK 9.0.1. VTK 8.2.0, VTK 9.0.1 and test program built with VC16.
This triggers the issue:
#include <Windows.h>
int main() {
BOOL setpath = SetDllDirectoryA("$(VTK_PATH)\\bin\\Debug");
HMODULE hMod = LoadLibraryA("vtkFiltersGeneral-9.0d.dll");
if (hMod) {
BOOL freed = FreeLibrary(hMod); // Access Violation.
}
return 0;
}
Stack trace:
vtkCommonCore-9.0d.dll!vtkCommonInformationKeyManager::ClassFinalize() Zeile 84 C++
vtkCommonCore-9.0d.dll!vtkCommonInformationKeyManager::~vtkCommonInformationKeyManager() Zeile 49 C++
vtkCommonCore-9.0d.dll!`dynamic atexit destructor for 'vtkCommonInformationKeyManagerInstance''() C++
ucrtbased.dll!00007ff97ed85107() Unbekannt
ucrtbased.dll!00007ff97ed84b15() Unbekannt
ucrtbased.dll!00007ff97ed84c4a() Unbekannt
ucrtbased.dll!00007ff97ed852b1() Unbekannt
vtkCommonCore-9.0d.dll!__scrt_dllmain_uninitialize_c() Zeile 399 C++
vtkCommonCore-9.0d.dll!dllmain_crt_process_detach(const bool is_terminating) Zeile 182 C++
vtkCommonCore-9.0d.dll!dllmain_crt_dispatch(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Zeile 220 C++
vtkCommonCore-9.0d.dll!dllmain_dispatch(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Zeile 293 C++
vtkCommonCore-9.0d.dll!_DllMainCRTStartup(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Zeile 335 C++
ntdll.dll!00007ff9d62c5021() Unbekannt
ntdll.dll!00007ff9d630da45() Unbekannt
ntdll.dll!00007ff9d62ced3b() Unbekannt
ntdll.dll!00007ff9d62cef8b() Unbekannt
ntdll.dll!00007ff9d62cf449() Unbekannt
ntdll.dll!00007ff9d62cf3c3() Unbekannt
KernelBase.dll!00007ff9d35e715e() Unbekannt
PCL FreeLibrary.exe!main() Zeile 39 C++
Incident site:
Watch:
*i 0x0000021e3875ca60 {Name=0x0000021e38764f10 "LABEL" Location=0x0000021e38765050 "vtkAnnotation" } vtkInformationKey * &
i {0x0000021e3875ca60 {Name=0x0000021e38764f10 "LABEL" Location=0x0000021e38765050 "vtkAnnotation" }} std::_Vector_iterator<std::_Vector_val<std::_Simple_types<vtkInformationKey *>>>
key 0x0000021e3875ca60 {Name=0x0000021e38764f10 "LABEL" Location=0x0000021e38765050 "vtkAnnotation" } vtkInformationKey *
vtkCommonInformationKeyManagerKeys 0x0000021e38730d50 { size=128 } vtkCommonInformationKeyManagerKeysType *